Skip to content

Commit

Permalink
Enables /mvn clean package liberty:run -Pliberty
Browse files Browse the repository at this point in the history
  • Loading branch information
Karm committed Jun 14, 2022
1 parent 8d6bdfd commit c7b9b94
Show file tree
Hide file tree
Showing 13 changed files with 383 additions and 114 deletions.
12 changes: 12 additions & 0 deletions Container/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ Building an image and running a container
Development workflow
====================

Locally without Docker, with Liberty
------------------------------------

```
./mvn clean package liberty:run -Pliberty
```

Open: http://localhost:9080/starter/index.xhtml

Note that the test suite requires Quarkus runtime, so it is
not supported to run tests with Liberty.

Locally without Docker, with Quarkus
------------------------------------

Expand Down
377 changes: 284 additions & 93 deletions pom.xml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/main/java/org/eclipse/microprofile/starter/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import java.util.Objects;
import java.util.Scanner;


/**
* @author Michal Karm Babacek <[email protected]>
*/
Expand All @@ -38,8 +38,8 @@ public class Version {

@PostConstruct
public void init() {
try (Scanner s = new Scanner(FilesLocator.class.getClassLoader()
.getResourceAsStream("/version.txt")).useDelimiter("\\A")) {
try (Scanner s = new Scanner(Objects.requireNonNull(
FilesLocator.class.getClassLoader().getResourceAsStream("/version.txt"))).useDelimiter("\\A")) {
git = s.hasNext() ? s.next() : "";
} catch (Exception e) {
LOG.error(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
*/
package org.eclipse.microprofile.starter.core.files;

import com.google.common.io.ByteStreams;
import org.eclipse.microprofile.starter.core.exception.TechnicalException;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -49,16 +49,15 @@ public byte[] processFile(String file, Set<String> alternatives) {
throw new FileResolutionException(file, alternatives);
}

String sourceFile = "/" + filesLocator.getTemplateFile(fileIndication);
final String sourceFile = "/" + filesLocator.getTemplateFile(fileIndication);
final ByteArrayOutputStream result = new ByteArrayOutputStream();

InputStream resource = FileCopyEngine.class.getResourceAsStream(sourceFile);
ByteArrayOutputStream result = new ByteArrayOutputStream();

try {
ByteStreams.copy(resource, result);
try (InputStream resource = FileCopyEngine.class.getResourceAsStream(sourceFile)) {
Objects.requireNonNull(resource).transferTo(result);
} catch (IOException e) {
throw new TechnicalException(e);
}

return result.toByteArray();
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/eclipse/microprofile/starter/log/AppContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.eclipse.microprofile.starter.log;

import javax.inject.Qualifier;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
public @interface AppContext {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.eclipse.microprofile.starter.log;

import org.eclipse.microprofile.context.ManagedExecutor;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;

@ApplicationScoped
public class ManagedExecutorProducer {

@Produces
@AppContext
ManagedExecutor createExecutor() {
return ManagedExecutor.builder().build();
}

void disposeExecutor(@Disposes @AppContext ManagedExecutor exec) {
exec.shutdownNow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.microprofile.starter.core.model.ModelManager;
import org.eclipse.microprofile.starter.core.model.OptionValue;
import org.eclipse.microprofile.starter.core.validation.PackageNameValidator;
import org.eclipse.microprofile.starter.log.AppContext;
import org.eclipse.microprofile.starter.log.ErrorLogger;
import org.eclipse.microprofile.starter.log.LoggingTask;
import org.eclipse.microprofile.starter.rest.model.MPOptionsAvailable;
Expand Down Expand Up @@ -204,7 +205,8 @@ private List<StandaloneMPSpec> defineStandaloneSpecs(MicroProfileVersion version
ZipFileCreator zipFileCreator;

@Inject
ManagedExecutor executor;
@AppContext
transient ManagedExecutor executor;

public Response readme(String ifNoneMatch) {
if (ifNoneMatch != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.microprofile.starter.core.model.MicroProfileVersion;
import org.eclipse.microprofile.starter.core.model.ModelManager;
import org.eclipse.microprofile.starter.core.model.OptionValue;
import org.eclipse.microprofile.starter.log.AppContext;
import org.eclipse.microprofile.starter.log.ErrorLogger;
import org.eclipse.microprofile.starter.log.LoggingTask;

Expand Down Expand Up @@ -89,7 +90,8 @@ public class GeneratorDataBean implements Serializable {
ErrorLogger errorLogger;

@Inject
ManagedExecutor executor;
@AppContext
transient ManagedExecutor executor;

private EngineData engineData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,19 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
servletResponse.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains");
servletResponse.setHeader("X-Content-Type-Options", "nosniff");
servletResponse.setHeader("X-Frame-Options", "DENY");
servletResponse.setHeader("Content-Security-Policy", "default-src: https: font-src 'https://fonts.googleapis.com';" +
"img-src 'self' https://microprofile.io; style-src 'self'; frame-ancestors 'none';");
servletResponse.setHeader("Content-Security-Policy", ""
+ "default-src 'self'; "
+ "script-src 'self' 'unsafe-inline' 'unsafe-eval' "
+ " https://use.fontawesome.com "
+ " https://kit.fontsawesome.com; "
+ "style-src 'self' 'unsafe-inline' "
+ " fonts.gstatic.com "
+ " fonts.googleapis.com "
+ " *.fontawesome.com; "
+ "img-src 'self' fonts.gstatic.com microprofile.io; "
+ "font-src 'self' fonts.gstatic.com fonts.googleapis.com *.fontsawesome.com; "
+ "connect-src 'self' fonts.gstatic.com fonts.googleapis.com *.fontsawesome.com; "
);
chain.doFilter(request, response);
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/liberty/config/server.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<server description="${project.name}">
<featureManager>
<feature>microProfile-4.1</feature>
<feature>webprofile-8.0</feature>
<feature>mpContextPropagation-1.2</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443"/>
<webApplication location="${project.name}.war" contextRoot="${app.context.root}">
<classloader apiTypeVisibility="+third-party" />
</webApplication>
</server>
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ span.ui-icon.ui-icon-triangle-1-s.ui-c::before {
padding: 9px 15px;
}


.ui-inputfield, .ui-selectonemenu.ui-widget.ui-state-default.ui-corner-all {
border-radius: 5px;
/* max-width: 280px; */
Expand Down Expand Up @@ -434,4 +433,4 @@ span.ui-chkbox-icon.ui-icon.ui-c.ui-icon-check {

.social i.fa:hover {
color: rgb(253, 183, 28);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ public static String getWorkspaceDir() {
public static File unzip(String location, String artifactId) throws InterruptedException, IOException {
ProcessBuilder pb;
if (IS_THIS_WINDOWS) {
pb = new ProcessBuilder("powershell", "-c", "Expand-Archive", "-Path", location, "-DestinationPath", WORKSPACE_DIR, "-Force");
pb = new ProcessBuilder(
"powershell", "-c", "Expand-Archive", "-Path", location, "-DestinationPath", WORKSPACE_DIR, "-Force");
} else {
pb = new ProcessBuilder("unzip", "-o", location, "-d", WORKSPACE_DIR);
}
Map<String, String> env = pb.environment();
env.put("PATH", System.getenv("PATH"));
pb.directory(new File(WORKSPACE_DIR));
File unzipLog = new File(WORKSPACE_DIR + File.separator + artifactId + "-unzip.log");
if (unzipLog.exists()) {
unzipLog.delete();
}
pb.redirectErrorStream(true);
pb.redirectOutput(ProcessBuilder.Redirect.to(unzipLog));
Process p = pb.start();
Expand All @@ -106,7 +110,8 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
try {
Files.delete(dir);
} catch (DirectoryNotEmptyException e) {
LOGGER.error(dir.toAbsolutePath() + " is not empty. That means someone is still writing to it. Stray Gradle daemon? Server?");
LOGGER.error(dir.toAbsolutePath()
+ " is not empty. That means someone is still writing to it. Stray Gradle daemon? Server?");
}
return FileVisitResult.CONTINUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -110,10 +111,9 @@ public static void archiveLog(String testClass, String testMethod, File log) thr
if (StringUtils.isBlank(testMethod)) {
throw new IllegalArgumentException("testMethod must not be blank");
}
Path destDir = Path.of(System.getProperties().get("basedir").toString(), "target", "archived-logs", testClass, testMethod);
final Path destDir = Path.of(System.getProperties().get("basedir").toString(), "target", "archived-logs", testClass, testMethod);
Files.createDirectories(destDir);
String filename = log.getName();
Files.copy(log.toPath(), Paths.get(destDir.toString(), filename));
Files.copy(log.toPath(), Paths.get(destDir.toString(), log.getName()), StandardCopyOption.REPLACE_EXISTING);
}

}

0 comments on commit c7b9b94

Please sign in to comment.