Search in sources :

Example 31 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.

the class ZipComparatorImpl method getDelta.

@Override
public CompoundArtifactDelta getDelta(File baseline, File reactor, MojoExecution execution) throws IOException {
    Map<String, ArtifactDelta> result = new LinkedHashMap<>();
    Collection<String> ignoredPatterns = new HashSet<>(IGNORED_PATTERNS);
    if (execution != null) {
        Xpp3Dom pluginConfiguration = (Xpp3Dom) execution.getPlugin().getConfiguration();
        if (pluginConfiguration != null) {
            Xpp3Dom ignoredPatternsNode = pluginConfiguration.getChild("ignoredPatterns");
            if (ignoredPatternsNode != null) {
                for (Xpp3Dom node : ignoredPatternsNode.getChildren()) {
                    ignoredPatterns.add(node.getValue());
                }
            }
        }
    }
    ZipFile jar = new ZipFile(baseline);
    try {
        ZipFile jar2 = new ZipFile(reactor);
        try {
            Map<String, ZipEntry> entries = toEntryMap(jar, ignoredPatterns);
            Map<String, ZipEntry> entries2 = toEntryMap(jar2, ignoredPatterns);
            Set<String> names = new TreeSet<>();
            names.addAll(entries.keySet());
            names.addAll(entries2.keySet());
            for (String name : names) {
                ZipEntry entry = entries.get(name);
                if (entry == null) {
                    result.put(name, new SimpleArtifactDelta("not present in baseline"));
                    continue;
                }
                ZipEntry entry2 = entries2.get(name);
                if (entry2 == null) {
                    result.put(name, new SimpleArtifactDelta("present in baseline only"));
                    continue;
                }
                InputStream is = jar.getInputStream(entry);
                try {
                    InputStream is2 = jar2.getInputStream(entry2);
                    try {
                        ContentsComparator comparator = comparators.get(getContentType(name));
                        ArtifactDelta differences = comparator.getDelta(is, is2, execution);
                        if (differences != null) {
                            result.put(name, differences);
                            continue;
                        }
                    } finally {
                        IOUtil.close(is2);
                    }
                } finally {
                    IOUtil.close(is);
                }
            }
        } finally {
            try {
                jar2.close();
            } catch (IOException e) {
            // too bad
            }
        }
    } finally {
        try {
            jar.close();
        } catch (IOException e) {
        // ouch
        }
    }
    return !result.isEmpty() ? new CompoundArtifactDelta("different", result) : null;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ZipFile(java.util.zip.ZipFile) TreeSet(java.util.TreeSet) ArtifactDelta(org.eclipse.tycho.artifactcomparator.ArtifactDelta) HashSet(java.util.HashSet)

Example 32 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.

the class EclipseInstallationLayout method getSites.

public Set<File> getSites() {
    Set<File> result = new LinkedHashSet<>();
    if (location == null) {
        return result;
    }
    if (new File(location, PLUGINS).isDirectory()) {
        result.add(location);
    }
    File platform = new File(location, "configuration/org.eclipse.update/platform.xml");
    if (platform.canRead()) {
        try {
            FileInputStream is = new FileInputStream(platform);
            try {
                XmlStreamReader reader = new XmlStreamReader(is);
                Xpp3Dom dom = Xpp3DomBuilder.build(reader);
                Xpp3Dom[] sites = dom.getChildren("site");
                for (Xpp3Dom site : sites) {
                    String enabled = site.getAttribute("enabled");
                    if (enabled == null || Boolean.parseBoolean(enabled)) {
                        File dir = parsePlatformURL(location, site.getAttribute("url"));
                        if (dir != null) {
                            result.add(dir);
                        }
                    }
                }
            } finally {
                is.close();
            }
        } catch (Exception e) {
            getLogger().warn("Exception parsing " + toString(platform), e);
        }
    }
    addLinks(result, location, new File(location, "links"));
    // deal with dropins folder
    result.add(dropinsLocation);
    File[] dropinsFiles = dropinsLocation.listFiles();
    if (dropinsFiles != null) {
        for (File dropinsFile : dropinsFiles) {
            File plugins = new File(dropinsFile, PLUGINS);
            if (plugins.isDirectory()) {
                result.add(plugins.getParentFile());
                continue;
            }
            plugins = new File(dropinsFile, "eclipse/plugins");
            if (plugins.isDirectory()) {
                result.add(plugins.getParentFile());
            }
        }
    }
    addLinks(result, location, dropinsLocation);
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) XmlStreamReader(org.codehaus.plexus.util.xml.XmlStreamReader) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 33 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.

the class DefaultTargetPlatformConfigurationReader method newTargetEnvironment.

private static TargetEnvironment newTargetEnvironment(Xpp3Dom environmentDom) throws TargetPlatformConfigurationException {
    Xpp3Dom osDom = environmentDom.getChild("os");
    if (osDom == null) {
        String message = "<os> element is missing within target-platform-configuration (element <environment>)";
        throw new TargetPlatformConfigurationException(message);
    }
    Xpp3Dom wsDom = environmentDom.getChild("ws");
    if (wsDom == null) {
        String message = "<ws> element is missing within target-platform-configuration (element <environment>)";
        throw new TargetPlatformConfigurationException(message);
    }
    Xpp3Dom archDom = environmentDom.getChild("arch");
    if (archDom == null) {
        String message = "<arch> element is missing within target-platform-configuration (element <environment>)";
        throw new TargetPlatformConfigurationException(message);
    }
    return new TargetEnvironment(osDom.getValue(), wsDom.getValue(), archDom.getValue());
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment)

Example 34 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.

the class DefaultTargetPlatformConfigurationReader method addTargetEnvironments.

private void addTargetEnvironments(TargetPlatformConfiguration result, MavenProject project, Xpp3Dom configuration) {
    try {
        TargetEnvironment deprecatedTargetEnvironmentSpec = getDeprecatedTargetEnvironment(configuration);
        if (deprecatedTargetEnvironmentSpec != null) {
            result.addEnvironment(deprecatedTargetEnvironmentSpec);
        }
        Xpp3Dom environmentsDom = configuration.getChild("environments");
        if (environmentsDom != null) {
            if (deprecatedTargetEnvironmentSpec != null) {
                String message = "Deprecated target-platform-configuration <environment> element must not be combined with new <environments> element; check the (inherited) configuration of " + project.getId();
                throw new RuntimeException(message);
            }
            for (Xpp3Dom environmentDom : environmentsDom.getChildren("environment")) {
                result.addEnvironment(newTargetEnvironment(environmentDom));
            }
        }
    } catch (TargetPlatformConfigurationException e) {
        throw new RuntimeException("target-platform-configuration error in project " + project.getId(), e);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment)

Example 35 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project tycho by eclipse.

the class DefaultTargetPlatformConfigurationReader method addTargetArtifact.

protected void addTargetArtifact(TargetPlatformConfiguration result, MavenSession session, MavenProject project, Xpp3Dom artifactDom) {
    Xpp3Dom groupIdDom = artifactDom.getChild("groupId");
    Xpp3Dom artifactIdDom = artifactDom.getChild("artifactId");
    Xpp3Dom versionDom = artifactDom.getChild("version");
    if (groupIdDom == null || artifactIdDom == null || versionDom == null) {
        throw new BuildFailureException("The target artifact configuration is invalid - <groupId>, <artifactId> and <version> are mandatory");
    }
    Xpp3Dom classifierDom = artifactDom.getChild("classifier");
    String groupId = groupIdDom.getValue();
    String artifactId = artifactIdDom.getValue();
    String version = versionDom.getValue();
    String classifier = classifierDom != null ? classifierDom.getValue() : null;
    File targetFile = null;
    for (MavenProject otherProject : session.getProjects()) {
        if (groupId.equals(otherProject.getGroupId()) && artifactId.equals(otherProject.getArtifactId()) && version.equals(otherProject.getVersion())) {
            String fileName;
            if (classifier == null) {
                // no classifier means target is provided using packaging type eclipse-target-definition
                fileName = artifactId;
            } else {
                // backward compat for target files manually installed via build-helper-maven-plugin
                fileName = classifier;
            }
            targetFile = new File(otherProject.getBasedir(), fileName + ".target");
            break;
        }
    }
    if (targetFile == null) {
        Artifact artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, "target", classifier);
        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
        request.setArtifact(artifact);
        request.setLocalRepository(session.getLocalRepository());
        request.setRemoteRepositories(project.getRemoteArtifactRepositories());
        repositorySystem.resolve(request);
        if (!artifact.isResolved()) {
            throw new RuntimeException("Could not resolve target platform specification artifact " + artifact);
        }
        targetFile = artifact.getFile();
    }
    result.addTarget(targetFile);
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenProject(org.apache.maven.project.MavenProject) BuildFailureException(org.eclipse.tycho.core.shared.BuildFailureException) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)156 Plugin (org.apache.maven.model.Plugin)39 File (java.io.File)26 ArrayList (java.util.ArrayList)18 PluginExecution (org.apache.maven.model.PluginExecution)18 IOException (java.io.IOException)13 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 MavenSession (org.apache.maven.execution.MavenSession)10 MavenProject (org.apache.maven.project.MavenProject)10 Model (org.apache.maven.model.Model)9 Reader (java.io.Reader)8 Build (org.apache.maven.model.Build)8 TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)8 BuildFailureException (org.eclipse.tycho.core.shared.BuildFailureException)8 MojoExecution (org.apache.maven.plugin.MojoExecution)7 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)7 Map (java.util.Map)6 Dependency (org.apache.maven.model.Dependency)6 StringReader (java.io.StringReader)5