use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.
the class MavenTest method shouldResolveSingleArtifact.
/**
* Ensure that {@link Maven} can resolve a single artifact (without a transitive dependency).
*/
@Test
public void shouldResolveSingleArtifact() {
LocalPlatform platform = LocalPlatform.get();
MetaClass metaClass = new JavaApplication.MetaClass();
OptionsByType optionsByType = OptionsByType.empty();
optionsByType.add(Maven.artifact("org.hamcrest:hamcrest-all:jar:1.3"));
Maven maven = optionsByType.get(Maven.class);
maven.onLaunching(platform, metaClass, optionsByType);
ClassPath classPath = optionsByType.getOrDefault(ClassPath.class, null);
assertThat(classPath, is(not(nullValue())));
assertThat(classPath.size(), is(1));
assertThat(classPath.toString(), containsString("hamcrest-all-1.3.jar"));
}
use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.
the class MavenTest method shouldOverrideArtifacts.
/**
* Ensure that {@link Maven} artifacts of the same group, artifactid, classified and extension
* are overridden when defined multiple times.
*/
@Test
public void shouldOverrideArtifacts() throws IOException {
LocalPlatform platform = LocalPlatform.get();
MetaClass metaClass = new JavaApplication.MetaClass();
OptionsByType optionsByType = OptionsByType.empty();
optionsByType.addAll(Maven.artifact("junit:junit:jar:4.10"), Maven.artifact("junit:junit:jar:4.11"), Maven.artifact("junit:junit:jar:4.12"));
Maven maven = optionsByType.get(Maven.class);
maven.onLaunching(platform, metaClass, optionsByType);
ClassPath classPath = optionsByType.getOrDefault(ClassPath.class, null);
assertThat(classPath, is(not(nullValue())));
// includes transitive dependencies
assertThat(classPath.size(), is(2));
assertThat(classPath.toString(), containsString("junit-4.12.jar"));
assertThat(classPath.toString(), containsString("hamcrest-core-1.3.jar"));
assertThat(classPath.toString(), not(containsString("junit-4.10.jar")));
assertThat(classPath.toString(), not(containsString("junit-4.11.jar")));
}
use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.
the class MavenTest method shouldIncludeAdditionalClassPaths.
/**
* Ensure that {@link Maven} includes additional {@link ClassPath}s when requested.
*/
@Test
public void shouldIncludeAdditionalClassPaths() throws IOException {
LocalPlatform platform = LocalPlatform.get();
MetaClass metaClass = new JavaApplication.MetaClass();
OptionsByType optionsByType = OptionsByType.empty();
optionsByType.addAll(Maven.artifact("junit:junit:jar:4.12"), Maven.include(ClassPath.ofClass(MavenTest.class)), Maven.include(ClassPath.ofResource("example-resource.txt")));
Maven maven = optionsByType.get(Maven.class);
maven.onLaunching(platform, metaClass, optionsByType);
ClassPath classPath = optionsByType.getOrDefault(ClassPath.class, null);
assertThat(classPath, is(not(nullValue())));
assertThat(classPath.size(), is(3));
assertThat(classPath.toString(), containsString("junit-4.12.jar"));
assertThat(classPath.toString(), containsString("hamcrest-core-1.3.jar"));
assertThat(classPath.toString(), containsString(ClassPath.ofClass(MavenTest.class).toString()));
assertThat(classPath.toString(), containsString(ClassPath.ofResource("example-resource.txt").toString()));
}
use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.
the class JavaDeployment method getDeploymentArtifacts.
@Override
public List<DeploymentArtifact> getDeploymentArtifacts(Platform platform, OptionsByType optionsByType) throws FileNotFoundException, IOException {
ArrayList<DeploymentArtifact> deploymentArtifacts = new ArrayList<DeploymentArtifact>();
File javaHomeFile = new File(System.getProperty("java.home"));
String javaHome = javaHomeFile.getCanonicalPath();
if (javaHomeFile.getName().equals("jre")) {
javaHome = javaHomeFile.getParentFile().getCanonicalPath();
}
if (autoDeployEnabled) {
// we'll use the class-path option to work out what to deploy
ClassPath classPath = optionsByType.get(ClassPath.class);
// include the application runner (if defined)
BedrockRunner bedrockRunner = optionsByType.get(BedrockRunner.class);
if (bedrockRunner != null && bedrockRunner.isEnabled()) {
// include the JavaApplicationLauncher
classPath = new ClassPath(classPath, ClassPath.ofClass(bedrockRunner.getClassOfRunner()));
// update the class path in the option
optionsByType.add(classPath);
}
for (String path : classPath) {
// we ignore leading and trailing spaces
path = path.trim();
if (this.excludeJDK && path.startsWith(javaHome)) {
continue;
}
if (path.endsWith("*")) {
// TODO: deal with wild-card based class paths
// (we need to copy all of the jars in the directory)
} else if (path.endsWith(".")) {
// TODO: deal with current directory based class paths
// (we need to copy all of the current directory, including sub-folders)
} else if (path.endsWith("..")) {
// TODO: deal with parent directory based class paths
// (is this even possible?)
} else {
// create a file based on the path
File file = new File(path);
if (file.exists()) {
if (file.isFile()) {
String fileName = file.getName();
// ensure that certain jars are not deployed
if (!excludeFileNames.contains(fileName.toLowerCase())) {
String destinationFile = file.getName();
DeploymentArtifact artifact = new DeploymentArtifact(file, new File(destinationFile));
deploymentArtifacts.add(artifact);
}
} else {
// create a temporary file in which to zip the contents of the folder
File temporaryFile = File.createTempFile("bedrock-deployment-", ".jar");
FileHelper.zip(Collections.singletonList(file), "", temporaryFile.getAbsolutePath());
DeploymentArtifact artifact = new DeploymentArtifact(temporaryFile, new File(temporaryFile.getName()), true);
deploymentArtifacts.add(artifact);
}
}
}
}
} else {
// TODO: non-automatic means we need to explicitly add the include list
}
return deploymentArtifacts;
}
use of com.oracle.bedrock.runtime.java.ClassPath in project oracle-bedrock by coherence-community.
the class RemoteJavaApplicationLauncher method onLaunching.
@Override
protected void onLaunching(OptionsByType optionsByType) {
// ----- establish default Profiles for this Platform (and Builder) -----
// java applications can automatically detect the following profiles
optionsByType.get(RemoteDebugging.class);
optionsByType.get(CommercialFeatures.class);
// ----- determine the remote classpath based on the deployment option -----
// when no deployment is specified we assume automatic
JavaDeployment deployment = (JavaDeployment) optionsByType.getOrSetDefault(Deployment.class, JavaDeployment.automatic());
if (deployment.isAutoDeployEnabled()) {
// determine the PlatformSeparators (assume unix if not defined)
PlatformSeparators separators = optionsByType.getOrSetDefault(PlatformSeparators.class, PlatformSeparators.forUnix());
// when an automatic deployment is specified,
// we use our modified class-path
// (which is where all of the deployed jars will be located)
String thisDir = ".";
String thisDirAllJars = thisDir + separators.getFileSeparator() + "*";
remoteClassPath = new ClassPath(thisDir, thisDirAllJars);
} else {
// when a non-automatic deployment is specified we use the specified class path
remoteClassPath = optionsByType.get(ClassPath.class);
}
// register the defined RemoteEventListeners before the application starts so they can
// immediately start receiving RemoteEvents
RemoteEvents remoteEvents = optionsByType.get(RemoteEvents.class);
remoteEvents.forEach((remoteEventListener, listenerOptions) -> remoteChannel.addListener(remoteEventListener, listenerOptions));
}
Aggregations