Skip to content

Commit ac4aa27

Browse files
committed
version 2.0.5
1 parent bc76c00 commit ac4aa27

7 files changed

Lines changed: 231 additions & 93 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>com.oracle</groupId>
1010
<artifactId>dragon</artifactId>
11-
<version>2.0.4</version>
11+
<version>2.0.5</version>
1212

1313
<name>Dragon Stack</name>
1414

@@ -19,7 +19,7 @@
1919
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2020
<maven-jar-plugin.version>2.4</maven-jar-plugin.version>
2121
<graalvm.version>20.2.0</graalvm.version>
22-
<oci.sdk.version>1.25.3</oci.sdk.version>
22+
<oci.sdk.version>1.25.4</oci.sdk.version>
2323
</properties>
2424

2525
<dependencies>

src/main/java/com/oracle/dragon/DragonStack.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.oracle.dragon.util.exception.DSException;
88

99
import static com.oracle.dragon.util.Console.*;
10+
import static com.oracle.dragon.util.Console.Style.ANSI_RESET;
11+
import static com.oracle.dragon.util.Console.Style.ANSI_UNDERLINE;
1012

1113
/**
1214
* DRAGON Stack Manager - Main entry point.
@@ -30,9 +32,10 @@ public static void main(final String[] args) {
3032

3133
session.loadLocalConfiguration(true);
3234

35+
// may override dbName
3336
session.analyzeCommandLineParameters(args);
3437

35-
session.loadConfiguration();
38+
session.loadConfigurationFile();
3639

3740
session.displayInformation();
3841

@@ -42,7 +45,8 @@ public static void main(final String[] args) {
4245
} catch (BmcException e) {
4346
if (e.isClientSide()) {
4447
System.err.println("A problem occurred on your side that prevented the operation to succeed!");
45-
e.printStackTrace();
48+
e.printStackTrace(System.err);
49+
displayHowToReportIssue();
4650
System.exit(-1000);
4751
} else {
4852
println("Status : " + e.getStatusCode());
@@ -55,6 +59,7 @@ public static void main(final String[] args) {
5559
println(Style.ANSI_RED + "Unhandled exception:");
5660
e.printStackTrace(System.err);
5761
}
62+
displayHowToReportIssue();
5863
} catch( ConfigurationFileNotFoundException | ConfigurationLoadException ce ) {
5964
ce.displayMessageAndExit(Style.ANSI_BRIGHT_CYAN + "duration: " + getDurationSince(totalDuration) + Style.ANSI_RESET, true);
6065
}
@@ -64,8 +69,16 @@ public static void main(final String[] args) {
6469
println(Style.ANSI_RED + "\n================================================================================");
6570
println(Style.ANSI_RED + "Unhandled exception:");
6671
e.printStackTrace(System.err);
72+
displayHowToReportIssue();
6773
} finally {
6874
println(Style.ANSI_BRIGHT_CYAN + "duration: " + getDurationSince(totalDuration));
6975
}
7076
}
77+
78+
public static void displayHowToReportIssue() {
79+
System.err.flush();
80+
println();
81+
println(ANSI_UNDERLINE + "Reporting issues:");
82+
println("Please report any issue (bug, enhancement request, documentation needs...) at " + ANSI_UNDERLINE + "http://bit.ly/DragonStack" + ANSI_RESET + " in the \"Issues\" tab.");
83+
}
7184
}

src/main/java/com/oracle/dragon/stacks/CodeGenerator.java

Lines changed: 116 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
public class CodeGenerator {
2929
private final StackType type;
3030
private final String name;
31+
private final String override;
3132
private final LocalDragonConfiguration localConfiguration;
3233
private DSSession.Section section;
3334
private StackMetadata stackMetadata;
3435

35-
public CodeGenerator(StackType type, String name, LocalDragonConfiguration localConfiguration) {
36+
public CodeGenerator(StackType type, String name, String override, LocalDragonConfiguration localConfiguration) {
3637
this.type = type;
3738
this.name = name;
39+
this.override = override;
3840
this.localConfiguration = localConfiguration;
3941
}
4042

@@ -49,68 +51,141 @@ public void work() throws DSException {
4951
dest.mkdirs();
5052
}
5153

52-
final String rootResourcesDir = "stacks/";
53-
54+
String rootResourcesDir = "stacks/";
5455
final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
55-
try {
56-
stackMetadata = mapper.readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream(rootResourcesDir + type.resourceDir + "/metadata.json"), StackMetadata.class);
5756

58-
if (stackMetadata.hasURL()) {
59-
downloadFile(stackMetadata.getUrl(), dest, stackMetadata.getSkipDirectoryLevel());
57+
if (override != null) {
58+
switch (type) {
59+
case REACT:
60+
section.print("overriding");
61+
try {
62+
rootResourcesDir = "https://raw.githubusercontent.com/loiclefevre/dragon/master/stacks/create-react-app/";
63+
stackMetadata = mapper.readValue(downloadFile(rootResourcesDir + override + "/metadata.json"), StackMetadata.class);
64+
65+
for (String fileName : stackMetadata.getFiles()) {
66+
if (fileName.endsWith("/")) {
67+
final File dir = new File(dest, fileName);
68+
if (!dir.exists()) dir.mkdirs();
69+
} else {
70+
final String path = fileName.substring(fileName.lastIndexOf('/') + 1);
71+
final String subDir = fileName.substring(0, fileName.length() - path.length());
72+
final InputStream inputStream = downloadFile(rootResourcesDir + override + "/data/" + fileName);
73+
if (inputStream == null) {
74+
throw new StackFileNotFoundException(type.humanName, fileName, rootResourcesDir + type.resourceDir + "/data/" + fileName);
75+
}
76+
extractFileContent(path, new File(dest, subDir), inputStream);
77+
}
78+
}
79+
} catch (IOException e) {
80+
throw new LoadStackMetadataException(type.humanName, e);
81+
}
82+
section.printlnOK(type.humanName + ": " + name+"#"+override);
83+
84+
85+
final ST st = new ST(
86+
new BufferedReader(
87+
new InputStreamReader(downloadFile(rootResourcesDir + override + "/message.st"), StandardCharsets.UTF_8))
88+
.lines()
89+
.collect(Collectors.joining("\n")), '<', '>');
90+
st.add("name", name);
91+
st.add("path", dest.getAbsolutePath());
92+
st.add("override", override);
93+
94+
System.out.println(st.render());
95+
96+
break;
6097
}
98+
} else {
99+
100+
try {
101+
stackMetadata = mapper.readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream(rootResourcesDir + type.resourceDir + "/metadata.json"), StackMetadata.class);
102+
103+
if (stackMetadata.hasURL()) {
104+
downloadFile(stackMetadata.getUrl(), dest, stackMetadata.getSkipDirectoryLevel());
105+
}
61106

62-
//System.out.println(stackMetadata.getFiles());
63-
64-
for (String fileName : stackMetadata.getFiles()) {
65-
if (fileName.endsWith("/")) {
66-
final File dir = new File(dest, fileName);
67-
if (!dir.exists()) dir.mkdirs();
68-
} else {
69-
final String path = fileName.substring(fileName.lastIndexOf('/') + 1);
70-
final String subDir = fileName.substring(0, fileName.length() - path.length());
71-
final InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(rootResourcesDir + type.resourceDir + "/data/" + fileName);
72-
if (inputStream == null) {
73-
throw new StackFileNotFoundException(type.humanName, fileName, rootResourcesDir + type.resourceDir + "/data/" + fileName);
107+
//System.out.println(stackMetadata.getFiles());
108+
109+
for (String fileName : stackMetadata.getFiles()) {
110+
if (fileName.endsWith("/")) {
111+
final File dir = new File(dest, fileName);
112+
if (!dir.exists()) dir.mkdirs();
113+
} else {
114+
final String path = fileName.substring(fileName.lastIndexOf('/') + 1);
115+
final String subDir = fileName.substring(0, fileName.length() - path.length());
116+
final InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(rootResourcesDir + type.resourceDir + "/data/" + fileName);
117+
if (inputStream == null) {
118+
throw new StackFileNotFoundException(type.humanName, fileName, rootResourcesDir + type.resourceDir + "/data/" + fileName);
119+
}
120+
extractFileContent(path, new File(dest, subDir), inputStream);
74121
}
75-
extractFileContent(path, new File(dest, subDir), inputStream);
76122
}
123+
124+
} catch (IOException e) {
125+
throw new LoadStackMetadataException(type.humanName, e);
77126
}
78127

79-
} catch (IOException e) {
80-
throw new LoadStackMetadataException(type.humanName, e);
81-
}
128+
section.printlnOK(type.humanName + ": " + name);
82129

83-
section.printlnOK(type.humanName + ": " + name);
130+
final Map<String, String> patchParameters = new HashMap<>();
84131

85-
final Map<String, String> patchParameters = new HashMap<>();
132+
if (type.codePatcher != null) {
133+
section = DSSession.Section.PostProcessingStack;
134+
section.print("patching");
135+
patchParameters.putAll(type.codePatcher.patch(dest, localConfiguration));
136+
section.printlnOK();
137+
}
86138

87-
if (type.codePatcher != null) {
88-
section = DSSession.Section.PostProcessingStack;
89-
section.print("patching");
90-
patchParameters.putAll(type.codePatcher.patch(dest, localConfiguration));
91-
section.printlnOK();
92-
}
139+
final ST st = new ST(
140+
new BufferedReader(
141+
new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(rootResourcesDir + type.resourceDir + "/message.st"), StandardCharsets.UTF_8))
142+
.lines()
143+
.collect(Collectors.joining("\n")), '<', '>');
144+
st.add("name", name);
145+
st.add("path", dest.getAbsolutePath());
93146

94-
final ST st = new ST(
95-
new BufferedReader(
96-
new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(rootResourcesDir + type.resourceDir + "/message.st"), StandardCharsets.UTF_8))
97-
.lines()
98-
.collect(Collectors.joining("\n")), '<', '>');
99-
st.add("name", name);
100-
st.add("path", dest.getAbsolutePath());
147+
for (String key : patchParameters.keySet()) {
148+
st.add(key, patchParameters.get(key));
149+
}
101150

102-
for (String key : patchParameters.keySet()) {
103-
st.add(key, patchParameters.get(key));
151+
System.out.println(st.render());
104152
}
153+
}
154+
155+
private InputStream downloadFile(String url) throws DSException {
156+
try {
157+
final HttpRequest requestDownload = HttpRequest.newBuilder()
158+
.uri(new URI(url))
159+
.setHeader("Pragma", "no-cache")
160+
.setHeader("Cache-Control", "no-store")
161+
.GET()
162+
.build();
163+
164+
final HttpResponse<InputStream> responseDownload = HttpClient
165+
.newBuilder()
166+
.version(HttpClient.Version.HTTP_1_1)
167+
.proxy(ProxySelector.getDefault())
168+
.followRedirects(HttpClient.Redirect.NORMAL)
169+
.build()
170+
.send(requestDownload, HttpResponse.BodyHandlers.ofInputStream());
171+
172+
if (responseDownload.statusCode() != 200) {
173+
section.printlnKO();
174+
throw new StackFileDownloadException(url, responseDownload.statusCode());
175+
}
105176

106-
System.out.println(st.render());
177+
return new BufferedInputStream(responseDownload.body(),1024*128);
178+
} catch (Exception e) {
179+
throw new StackFileDownloadException(url, e);
180+
}
107181
}
108182

109183
private void downloadFile(String url, File dest, int skipDirLevel) throws DSException {
110184
try {
111185
final HttpRequest requestDownload = HttpRequest.newBuilder()
112186
.uri(new URI(url))
113187
.setHeader("Pragma", "no-cache")
188+
.setHeader("Cache-Control", "no-store")
114189
.GET()
115190
.build();
116191

0 commit comments

Comments
 (0)