Search in sources :

Example 26 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor in project tycho by eclipse.

the class AbstractArtifactDependencyWalker method traverseFeature.

protected void traverseFeature(FeatureRef ref, ArtifactDependencyVisitor visitor, WalkbackPath visited) {
    ArtifactDescriptor artifact = artifacts.getArtifact(ArtifactType.TYPE_ECLIPSE_FEATURE, ref.getId(), ref.getVersion());
    if (artifact != null) {
        if (visited.visited(artifact.getKey())) {
            return;
        }
        visited.enter(artifact);
        try {
            File location = artifact.getLocation();
            Feature feature = Feature.loadFeature(location);
            traverseFeature(location, feature, ref, visitor, visited);
        } finally {
            visited.leave(artifact);
        }
    } else {
        visitor.missingFeature(ref, visited.getWalkback());
    }
}
Also used : ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) File(java.io.File) Feature(org.eclipse.tycho.model.Feature)

Example 27 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor in project tycho by eclipse.

the class RepositoryReferenceTool method addTargetPlatformRepository.

/**
 * Restores the p2 metadata view on the module's build target platform that was calculated
 * during the initial dependency resolution (see
 * org.eclipse.tycho.p2.resolver.P2ResolverImpl.toResolutionResult(...)).
 */
private void addTargetPlatformRepository(RepositoryReferences sources, MavenSession session, MavenProject project) throws MojoExecutionException, MojoFailureException {
    try {
        File repositoryLocation = new File(project.getBuild().getDirectory(), "targetPlatformRepository");
        repositoryLocation.mkdirs();
        FileOutputStream stream = new FileOutputStream(new File(repositoryLocation, "content.xml"));
        try {
            MetadataSerializable serializer = osgiServices.getService(MetadataSerializable.class);
            TargetPlatform targetPlatform = TychoProjectUtils.getTargetPlatform(project);
            DependencyResolver resolver = dependencyResolverLocator.lookupDependencyResolver(project);
            TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
            DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration();
            DependencyArtifacts dependencyArtifacts = resolver.resolveDependencies(session, project, targetPlatform, DefaultReactorProject.adapt(session), resolverConfiguration);
            // this contains dependency-only metadata for 'this' project
            Set<Object> targetPlatformInstallableUnits = new HashSet<>(dependencyArtifacts.getInstallableUnits());
            for (ArtifactDescriptor artifact : dependencyArtifacts.getArtifacts()) {
                ReactorProject otherProject = artifact.getMavenProject();
                if (otherProject == null) {
                    // can't really happen
                    continue;
                }
                File artifactXml = otherProject.getArtifact(RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS);
                if (artifactXml != null && artifactXml.isFile()) {
                    sources.addArtifactRepository(artifactXml.getParentFile());
                }
            }
            serializer.serialize(stream, targetPlatformInstallableUnits);
        } finally {
            stream.close();
        }
        sources.addMetadataRepository(repositoryLocation);
    } catch (IOException e) {
        throw new MojoExecutionException("I/O exception while writing the build target platform to disk", e);
    }
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ReactorProject(org.eclipse.tycho.ReactorProject) IOException(java.io.IOException) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) DependencyResolverConfiguration(org.eclipse.tycho.core.DependencyResolverConfiguration) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) MetadataSerializable(org.eclipse.tycho.p2.metadata.MetadataSerializable) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) FileOutputStream(java.io.FileOutputStream) TargetPlatform(org.eclipse.tycho.artifacts.TargetPlatform) File(java.io.File) HashSet(java.util.HashSet)

Example 28 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor in project tycho by eclipse.

the class ArtifactDependencyVisitor method newRuntimeException.

protected RuntimeException newRuntimeException(String message, String missing, List<ArtifactDescriptor> walkback) {
    StringBuilder sb = new StringBuilder();
    sb.append(message).append(" ").append(missing).append("; Path to dependency:\n");
    for (ArtifactDescriptor artifact : walkback) {
        sb.append("  ").append(artifact.toString()).append("\n");
    }
    return new RuntimeException(sb.toString());
}
Also used : ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor)

Example 29 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor in project tycho by eclipse.

the class GeneratePomsMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    List<File> baseDirs = getBaseDirs();
    if (getLog().isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("baseDir=").append(toString(baseDir)).append('\n');
        sb.append("extraDirs=").append(extraDirs).append('\n');
        for (int i = 0; i < baseDirs.size(); i++) {
            sb.append("dir[").append(i).append("]=").append(toString(baseDirs.get(i))).append('\n');
        }
        getLog().debug(sb.toString());
    }
    // find all candidate folders
    List<File> candidateDirs = new ArrayList<>();
    for (File basedir : baseDirs) {
        findAndAddCandidates(candidateDirs, basedir);
    }
    // find all root projects
    List<File> rootProjects = getRootProjects();
    if (getLog().isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("rootProjects=").append(this.rootProjects);
        for (int i = 0; i < rootProjects.size(); i++) {
            sb.append("rootProject[").append(i).append("]=").append(toString(rootProjects.get(i))).append('\n');
        }
        getLog().debug(sb.toString());
    }
    for (File dir : candidateDirs) {
        if (isPluginProject(dir)) {
            OsgiManifest mf = bundleReader.loadManifest(dir);
            platform.addArtifactFile(mf.toArtifactKey(), dir, null);
        }
    }
    // testSuite
    File testSuiteLocation = null;
    if (testSuite != null) {
        ArtifactDescriptor bundle = platform.getArtifact(ArtifactType.TYPE_ECLIPSE_PLUGIN, testSuite, null);
        if (bundle != null) {
            testSuiteLocation = bundle.getLocation();
        }
    }
    Set<File> projects = new LinkedHashSet<>();
    // always add baseDir
    projects.add(baseDirs.get(0));
    if (rootProjects.size() > 0) {
        if (testSuiteLocation != null) {
            rootProjects.add(testSuiteLocation);
        }
        for (File rootProject : rootProjects) {
            getLog().info("Resolving root project " + toString(rootProject));
            if (isUpdateSiteProject(rootProject)) {
                projects.addAll(getSiteFeaturesAndPlugins(rootProject));
                projects.add(rootProject);
            } else if (isFeatureProject(rootProject)) {
                projects.addAll(getFeatureFeaturesAndPlugins(rootProject));
                projects.add(rootProject);
            } else if (isPluginProject(rootProject)) {
                // TODO getPluginAndDependencies
                addPluginImpl(projects, rootProject);
                projects.add(rootProject);
            } else {
                getLog().warn("Unsupported root project " + toString(rootProject));
            }
        }
    } else {
        projects.addAll(candidateDirs);
    }
    if (getLog().isDebugEnabled()) {
        getLog().debug("Collected " + projects.size() + " projects");
        for (File dir : projects) {
            getLog().debug("\t" + toString(dir));
        }
    }
    // write poms
    Iterator<File> projectIter = projects.iterator();
    File parentDir = projectIter.next();
    if (!projectIter.hasNext()) {
        if (isProjectDir(parentDir)) {
            generatePom(null, parentDir);
        } else {
            throw new MojoExecutionException("Could not find any valid projects");
        }
    } else {
        Model parent = readPomTemplate("parent-pom.xml");
        parent.setGroupId(groupId);
        parent.setArtifactId(parentDir.getName());
        parent.setVersion(version);
        while (projectIter.hasNext()) {
            File projectDir = projectIter.next();
            generatePom(parent, projectDir);
            parent.addModule(getModuleName(parentDir, projectDir));
        }
        reorderModules(parent, parentDir, testSuiteLocation);
        addTychoExtension(parent);
        writePom(parentDir, parent);
        generateAggregatorPoms(testSuiteLocation);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ArrayList(java.util.ArrayList) Model(org.apache.maven.model.Model) OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest) File(java.io.File)

Example 30 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor in project tycho by eclipse.

the class ProductExportMojo method copyExecutable.

private void copyExecutable(TargetEnvironment environment, File target) throws MojoExecutionException, MojoFailureException {
    getLog().debug("Creating launcher");
    ArtifactDescriptor artifact = getDependencyArtifacts().getArtifact(ArtifactType.TYPE_ECLIPSE_FEATURE, "org.eclipse.equinox.executable", null);
    if (artifact == null) {
        throw new MojoExecutionException("Native launcher is not found for " + environment.toString());
    }
    File location = artifact.getLocation();
    String os = environment.getOs();
    String ws = environment.getWs();
    String arch = environment.getArch();
    try {
        String launcherRelPath = "bin/" + ws + "/" + os + "/" + arch + "/";
        String excludes = "**/eclipsec*";
        if (location.isDirectory()) {
            copyDirectory(new File(location, launcherRelPath), target, excludes);
        } else {
            unzipDirectory(location, launcherRelPath, target, excludes);
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to copy launcher executable", e);
    }
    File launcher = getLauncher(environment, target);
    // make launcher executable
    try {
        getLog().debug("running chmod");
        ArchiveEntryUtils.chmod(launcher, 0755, logger);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Unable to make launcher being executable", e);
    }
    File osxEclipseApp = null;
    // Rename launcher
    if (productConfiguration.getLauncher() != null && productConfiguration.getLauncher().getName() != null) {
        String launcherName = productConfiguration.getLauncher().getName();
        String newName = launcherName;
        // win32 has extensions
        if (PlatformPropertiesUtils.OS_WIN32.equals(os)) {
            String extension = FileUtils.getExtension(launcher.getAbsolutePath());
            newName = launcherName + "." + extension;
        } else if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) {
            // the launcher is renamed to "eclipse", because
            // this is the value of the CFBundleExecutable
            // property within the Info.plist file.
            // see http://jira.codehaus.org/browse/MNGECLIPSE-1087
            newName = "eclipse";
        }
        getLog().debug("Renaming launcher to " + newName);
        File newLauncher = new File(launcher.getParentFile(), newName);
        if (!launcher.renameTo(newLauncher)) {
            throw new MojoExecutionException("Could not rename native launcher to " + newName);
        }
        launcher = newLauncher;
        // see http://jira.codehaus.org/browse/MNGECLIPSE-1087
        if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) {
            newName = launcherName + ".app";
            getLog().debug("Renaming Eclipse.app to " + newName);
            File eclipseApp = new File(target, "Eclipse.app");
            osxEclipseApp = new File(eclipseApp.getParentFile(), newName);
            eclipseApp.renameTo(osxEclipseApp);
        // ToDo: the "Info.plist" file must be patched, so that the
        // property "CFBundleName" has the value of the
        // launcherName variable
        }
    }
    // icons
    if (productConfiguration.getLauncher() != null) {
        if (PlatformPropertiesUtils.OS_WIN32.equals(os)) {
            getLog().debug("win32 icons");
            List<String> icons = productConfiguration.getW32Icons();
            if (icons != null) {
                getLog().debug(icons.toString());
                try {
                    String[] args = new String[icons.size() + 1];
                    args[0] = launcher.getAbsolutePath();
                    int pos = 1;
                    for (String string : icons) {
                        args[pos] = string;
                        pos++;
                    }
                    IconExe.main(args);
                } catch (Exception e) {
                    throw new MojoExecutionException("Unable to replace icons", e);
                }
            } else {
                getLog().debug("icons is null");
            }
        } else if (PlatformPropertiesUtils.OS_LINUX.equals(os)) {
            String icon = productConfiguration.getLinuxIcon();
            if (icon != null) {
                try {
                    File sourceXPM = new File(project.getBasedir(), removeFirstSegment(icon));
                    File targetXPM = new File(launcher.getParentFile(), "icon.xpm");
                    FileUtils.copyFile(sourceXPM, targetXPM);
                } catch (IOException e) {
                    throw new MojoExecutionException("Unable to create ico.xpm", e);
                }
            }
        } else if (PlatformPropertiesUtils.OS_MACOSX.equals(os)) {
            String icon = productConfiguration.getMacIcon();
            if (icon != null) {
                try {
                    if (osxEclipseApp == null) {
                        osxEclipseApp = new File(target, "Eclipse.app");
                    }
                    File source = new File(project.getBasedir(), removeFirstSegment(icon));
                    File targetFolder = new File(osxEclipseApp, "/Resources/" + source.getName());
                    FileUtils.copyFile(source, targetFolder);
                    // Modify eclipse.ini
                    File iniFile = new File(osxEclipseApp + "/Contents/MacOS/eclipse.ini");
                    if (iniFile.exists() && iniFile.canWrite()) {
                        StringBuffer buf = readFileToString(iniFile);
                        int pos = buf.indexOf("Eclipse.icns");
                        buf.replace(pos, pos + 12, source.getName());
                        writeStringToFile(iniFile, buf.toString());
                    }
                } catch (Exception e) {
                    throw new MojoExecutionException("Unable to create macosx icon", e);
                }
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileNotFoundException(java.io.FileNotFoundException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)32 File (java.io.File)20 ArtifactKey (org.eclipse.tycho.ArtifactKey)13 ReactorProject (org.eclipse.tycho.ReactorProject)10 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 IOException (java.io.IOException)4 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)4 DefaultArtifactDescriptor (org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor)4 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 PluginDescription (org.eclipse.tycho.core.PluginDescription)3 Version (org.osgi.framework.Version)3 FileOutputStream (java.io.FileOutputStream)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Properties (java.util.Properties)2 ZipFile (java.util.zip.ZipFile)2