Search in sources :

Example 1 with ClassPath

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"));
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) MetaClass(com.oracle.bedrock.runtime.MetaClass) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 2 with ClassPath

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")));
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) MetaClass(com.oracle.bedrock.runtime.MetaClass) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 3 with ClassPath

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()));
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) MetaClass(com.oracle.bedrock.runtime.MetaClass) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 4 with ClassPath

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;
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) BedrockRunner(com.oracle.bedrock.runtime.java.options.BedrockRunner) ArrayList(java.util.ArrayList) DeploymentArtifact(com.oracle.bedrock.runtime.remote.DeploymentArtifact) File(java.io.File)

Example 5 with ClassPath

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));
}
Also used : PlatformSeparators(com.oracle.bedrock.runtime.options.PlatformSeparators) ClassPath(com.oracle.bedrock.runtime.java.ClassPath) RemoteEvents(com.oracle.bedrock.runtime.java.options.RemoteEvents) Deployment(com.oracle.bedrock.runtime.remote.options.Deployment) JavaDeployment(com.oracle.bedrock.runtime.remote.java.options.JavaDeployment) JavaDeployment(com.oracle.bedrock.runtime.remote.java.options.JavaDeployment)

Aggregations

ClassPath (com.oracle.bedrock.runtime.java.ClassPath)29 Test (org.junit.Test)21 File (java.io.File)12 TestClasses (com.oracle.bedrock.testsupport.junit.options.TestClasses)10 AbstractJUnit4Test (com.oracle.bedrock.testsupport.junit.AbstractJUnit4Test)9 JUnit3Test (com.oracle.bedrock.testsupport.junit.JUnit3Test)9 JUnit4Test (com.oracle.bedrock.testsupport.junit.JUnit4Test)9 RunWithAnnotatedTest (com.oracle.bedrock.testsupport.junit.RunWithAnnotatedTest)9 OptionsByType (com.oracle.bedrock.OptionsByType)4 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)4 MetaClass (com.oracle.bedrock.runtime.MetaClass)4 JavaAgent (com.oracle.bedrock.runtime.java.options.JavaAgent)3 DummyClass (classloader.child.DummyClass)2 AvailablePortIterator (com.oracle.bedrock.runtime.network.AvailablePortIterator)2 JUnit3Suite (com.oracle.bedrock.testsupport.junit.JUnit3Suite)2 Capture (com.oracle.bedrock.util.Capture)2 LinkedHashSet (java.util.LinkedHashSet)2 DummyParentLoadedClass (classloader.parent.DummyParentLoadedClass)1 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)1 ContainerClassLoader (com.oracle.bedrock.runtime.java.container.ContainerClassLoader)1