Search in sources :

Example 1 with BuildOutputJar

use of org.eclipse.tycho.core.osgitools.project.BuildOutputJar in project tycho by eclipse.

the class TestMojo method getBuildOutputDirectories.

private String getBuildOutputDirectories() {
    StringBuilder sb = new StringBuilder();
    ReactorProject reactorProject = getReactorProject();
    sb.append(reactorProject.getOutputDirectory());
    sb.append(',').append(reactorProject.getTestOutputDirectory());
    for (BuildOutputJar outputJar : osgiBundle.getEclipsePluginProject(reactorProject).getOutputJars()) {
        if (".".equals(outputJar.getName())) {
            // handled above
            continue;
        }
        appendCommaSeparated(sb, outputJar.getOutputDirectory().getAbsolutePath());
    }
    return sb.toString();
}
Also used : BuildOutputJar(org.eclipse.tycho.core.osgitools.project.BuildOutputJar) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject)

Example 2 with BuildOutputJar

use of org.eclipse.tycho.core.osgitools.project.BuildOutputJar in project tycho by eclipse.

the class OsgiBundleProject method getThisProjectClasspath.

/**
 * Returns project compile classpath entries.
 */
private List<File> getThisProjectClasspath(ArtifactDescriptor bundle, ReactorProject project) {
    LinkedHashSet<File> classpath = new LinkedHashSet<>();
    EclipsePluginProject pdeProject = getEclipsePluginProject(project);
    Map<String, BuildOutputJar> outputJars = pdeProject.getOutputJarMap();
    // unconditionally add all output jars (even if does not exist or not on Bundle-ClassPath)
    for (BuildOutputJar jar : outputJars.values()) {
        classpath.add(jar.getOutputDirectory());
    }
    // => assume it's checked into SCM or will be copied here later during build
    for (String cp : parseBundleClasspath(bundle)) {
        if (!outputJars.containsKey(cp)) {
            classpath.add(new File(project.getBasedir(), cp));
        }
    }
    return new ArrayList<>(classpath);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EclipsePluginProject(org.eclipse.tycho.core.osgitools.project.EclipsePluginProject) BuildOutputJar(org.eclipse.tycho.core.osgitools.project.BuildOutputJar) ArrayList(java.util.ArrayList) File(java.io.File)

Example 3 with BuildOutputJar

use of org.eclipse.tycho.core.osgitools.project.BuildOutputJar in project tycho by eclipse.

the class PackagePluginMojo method createPluginJar.

private File createPluginJar() throws MojoExecutionException {
    try {
        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(jarArchiver);
        File pluginFile = new File(buildDirectory, finalName + ".jar");
        if (pluginFile.exists()) {
            pluginFile.delete();
        }
        BuildProperties buildProperties = pdeProject.getBuildProperties();
        List<String> binIncludesList = buildProperties.getBinIncludes();
        List<String> binExcludesList = buildProperties.getBinExcludes();
        // 1. additional filesets should win over bin.includes, so we add them first
        if (additionalFileSets != null) {
            for (DefaultFileSet fileSet : additionalFileSets) {
                if (fileSet.getDirectory() != null && fileSet.getDirectory().isDirectory()) {
                    archiver.getArchiver().addFileSet(fileSet);
                }
            }
        }
        List<String> binIncludesIgnoredForValidation = new ArrayList<>();
        // 2. handle dir classpath entries and "."
        for (BuildOutputJar outputJar : pdeProject.getOutputJarMap().values()) {
            String jarName = outputJar.getName();
            if (binIncludesList.contains(jarName) && outputJar.isDirClasspathEntry()) {
                binIncludesIgnoredForValidation.add(jarName);
                String prefix = ".".equals(jarName) ? "" : jarName;
                archiver.getArchiver().addDirectory(outputJar.getOutputDirectory(), prefix);
            }
        }
        // 3. handle nested jars and included resources
        checkBinIncludesExist(buildProperties, binIncludesIgnoredForValidation.toArray(new String[0]));
        archiver.getArchiver().addFileSet(getFileSet(project.getBasedir(), binIncludesList, binExcludesList));
        File manifest = updateManifest();
        if (manifest.exists()) {
            archive.setManifestFile(manifest);
        }
        archiver.setOutputFile(pluginFile);
        if (!archive.isForced()) {
            // optimized archive creation not supported for now because of build qualifier mismatch issues
            // see TYCHO-502
            getLog().warn("ignoring unsupported archive forced = false parameter.");
            archive.setForced(true);
        }
        archiver.createArchive(session, project, archive);
        return pluginFile;
    } catch (IOException e) {
        throw new MojoExecutionException("Error assembling JAR", e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Error assembling JAR", e);
    } catch (ManifestException e) {
        throw new MojoExecutionException("Error assembling JAR", e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("Error assembling JAR", e);
    }
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArrayList(java.util.ArrayList) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) BuildProperties(org.eclipse.tycho.core.shared.BuildProperties) BuildOutputJar(org.eclipse.tycho.core.osgitools.project.BuildOutputJar) File(java.io.File)

Example 4 with BuildOutputJar

use of org.eclipse.tycho.core.osgitools.project.BuildOutputJar in project tycho by eclipse.

the class OsgiBundleProject method getOtherProjectClasspath.

/**
 * Returns bundle classpath entries. If <code>nestedPath</code> is not <code>null</code>,
 * returns single class folder that corresponds specified nestedPath. If <code>nestedPath</code>
 * is <code>null</code>, returns entries specified in Bundle-ClassPath.
 */
private List<File> getOtherProjectClasspath(ArtifactDescriptor bundle, ReactorProject otherProject, String nestedPath) {
    LinkedHashSet<File> classpath = new LinkedHashSet<>();
    EclipsePluginProject pdeProject = getEclipsePluginProject(otherProject);
    Map<String, BuildOutputJar> outputJars = pdeProject.getOutputJarMap();
    String[] bundleClassPath;
    if (nestedPath == null) {
        bundleClassPath = parseBundleClasspath(bundle);
    } else {
        bundleClassPath = new String[] { nestedPath };
    }
    for (String cp : bundleClassPath) {
        if (outputJars.containsKey(cp)) {
            // add output folder even if it does not exist (yet)
            classpath.add(outputJars.get(cp).getOutputDirectory());
        } else {
            // no associated output folder
            // => assume it's checked into SCM or will be copied here later during build
            classpath.add(new File(otherProject.getBasedir(), cp));
        }
    }
    return new ArrayList<>(classpath);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EclipsePluginProject(org.eclipse.tycho.core.osgitools.project.EclipsePluginProject) BuildOutputJar(org.eclipse.tycho.core.osgitools.project.BuildOutputJar) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with BuildOutputJar

use of org.eclipse.tycho.core.osgitools.project.BuildOutputJar in project tycho by eclipse.

the class OsgiBundleProject method addExtraClasspathEntries.

private void addExtraClasspathEntries(List<ClasspathEntry> classpath, ReactorProject project, DependencyArtifacts artifacts) {
    EclipsePluginProject pdeProject = getEclipsePluginProject(project);
    Collection<BuildOutputJar> outputJars = pdeProject.getOutputJarMap().values();
    for (BuildOutputJar buildOutputJar : outputJars) {
        List<String> entries = buildOutputJar.getExtraClasspathEntries();
        for (String entry : entries) {
            Pattern platformURL = Pattern.compile("platform:/(plugin|fragment)/([^/]*)/*(.*)");
            Matcher m = platformURL.matcher(entry.trim());
            String bundleId = null;
            String path = null;
            if (m.matches()) {
                bundleId = m.group(2).trim();
                path = m.group(3).trim();
                if (path != null && path.length() <= 0) {
                    path = null;
                }
                ArtifactDescriptor matchingBundle = artifacts.getArtifact(ArtifactType.TYPE_ECLIPSE_PLUGIN, bundleId, null);
                if (matchingBundle != null) {
                    List<File> locations;
                    if (matchingBundle.getMavenProject() != null) {
                        locations = getOtherProjectClasspath(matchingBundle, matchingBundle.getMavenProject(), path);
                    } else if (path != null) {
                        locations = getBundleEntry(matchingBundle, path);
                    } else {
                        locations = getBundleClasspath(matchingBundle);
                    }
                    classpath.add(new DefaultClasspathEntry(matchingBundle.getMavenProject(), matchingBundle.getKey(), locations, null));
                } else {
                    getLogger().warn("Missing extra classpath entry " + entry.trim());
                }
            } else {
                entry = entry.trim();
                File file = new File(project.getBasedir(), entry).getAbsoluteFile();
                if (file.exists()) {
                    List<File> locations = Collections.singletonList(file);
                    ArtifactKey projectKey = getArtifactKey(project);
                    classpath.add(new DefaultClasspathEntry(project, projectKey, locations, null));
                } else {
                    getLogger().warn("Missing extra classpath entry " + entry);
                }
            }
        }
    }
}
Also used : EclipsePluginProject(org.eclipse.tycho.core.osgitools.project.EclipsePluginProject) Pattern(java.util.regex.Pattern) ArtifactKey(org.eclipse.tycho.ArtifactKey) BuildOutputJar(org.eclipse.tycho.core.osgitools.project.BuildOutputJar) Matcher(java.util.regex.Matcher) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) File(java.io.File)

Aggregations

BuildOutputJar (org.eclipse.tycho.core.osgitools.project.BuildOutputJar)8 File (java.io.File)6 ArrayList (java.util.ArrayList)4 EclipsePluginProject (org.eclipse.tycho.core.osgitools.project.EclipsePluginProject)3 LinkedHashSet (java.util.LinkedHashSet)2 IOException (java.io.IOException)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 MavenArchiver (org.apache.maven.archiver.MavenArchiver)1 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)1 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)1 DefaultFileSet (org.codehaus.plexus.archiver.util.DefaultFileSet)1 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)1 ArtifactKey (org.eclipse.tycho.ArtifactKey)1 ReactorProject (org.eclipse.tycho.ReactorProject)1 SourcepathEntry (org.eclipse.tycho.classpath.SourcepathEntry)1 StandardExecutionEnvironment (org.eclipse.tycho.core.ee.StandardExecutionEnvironment)1 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)1