ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlboud...@apache.org
Subject svn commit: r1498803 - in /ant/easyant/core/trunk/src/main: java/org/apache/easyant/tasks/IvyDependencyUpdateChecker.java java/org/apache/easyant/tasks/PluginUpdateChecker.java resources/org/apache/easyant/antlib.xml
Date Tue, 02 Jul 2013 07:00:36 GMT
Author: jlboudart
Date: Tue Jul  2 07:00:36 2013
New Revision: 1498803

URL: http://svn.apache.org/r1498803
Log:
Introduce  plugin update checker task and dependency update checker task (backported from
ivy trunk until next release)

Added:
    ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/IvyDependencyUpdateChecker.java
    ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginUpdateChecker.java
Modified:
    ant/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml

Added: ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/IvyDependencyUpdateChecker.java
URL: http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/IvyDependencyUpdateChecker.java?rev=1498803&view=auto
==============================================================================
--- ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/IvyDependencyUpdateChecker.java
(added)
+++ ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/IvyDependencyUpdateChecker.java
Tue Jul  2 07:00:36 2013
@@ -0,0 +1,210 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.easyant.tasks;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.ivy.ant.IvyPostResolveTask;
+import org.apache.ivy.core.module.descriptor.Configuration;
+import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
+import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
+import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.report.ResolveReport;
+import org.apache.ivy.core.resolve.IvyNode;
+import org.apache.ivy.core.resolve.ResolveOptions;
+import org.apache.tools.ant.BuildException;
+
+/**
+ * Backport of IvyDependencyUpdateChecker until a new version of ivy will be released
+ * 
+ */
+public class IvyDependencyUpdateChecker extends IvyPostResolveTask {
+
+    private String revisionToCheck = "latest.integration";
+
+    private boolean download = false;
+
+    private boolean checkIfChanged = false;
+
+    private boolean showTransitive = false;
+
+    public void doExecute() throws BuildException {
+        prepareAndCheck();
+
+        ModuleDescriptor originalModuleDescriptor = getResolvedReport().getModuleDescriptor();
+        // clone module descriptor
+        DefaultModuleDescriptor latestModuleDescriptor = new DefaultModuleDescriptor(
+                originalModuleDescriptor.getModuleRevisionId(), originalModuleDescriptor.getStatus(),
+                originalModuleDescriptor.getPublicationDate());
+        // copy configurations
+        for (int i = 0; i < originalModuleDescriptor.getConfigurations().length; i++)
{
+            Configuration configuration = originalModuleDescriptor.getConfigurations()[i];
+            latestModuleDescriptor.addConfiguration(configuration);
+        }
+        // clone dependency and add new one with the requested revisionToCheck
+        for (int i = 0; i < originalModuleDescriptor.getDependencies().length; i++) {
+            DependencyDescriptor dependencyDescriptor = originalModuleDescriptor.getDependencies()[i];
+            ModuleRevisionId upToDateMrid = ModuleRevisionId.newInstance(
+                    dependencyDescriptor.getDependencyRevisionId(), revisionToCheck);
+            latestModuleDescriptor.addDependency(dependencyDescriptor.clone(upToDateMrid));
+        }
+
+        // resolve
+        ResolveOptions resolveOptions = new ResolveOptions();
+        resolveOptions.setDownload(isDownload());
+        resolveOptions.setLog(getLog());
+        resolveOptions.setConfs(splitConfs(getConf()));
+        resolveOptions.setCheckIfChanged(checkIfChanged);
+
+        ResolveReport latestReport;
+        try {
+            latestReport = getIvyInstance().getResolveEngine().resolve(latestModuleDescriptor,
resolveOptions);
+
+            displayDependencyUpdates(getResolvedReport(), latestReport);
+            if (showTransitive) {
+                displayNewDependencyOnLatest(getResolvedReport(), latestReport);
+                displayMissingDependencyOnLatest(getResolvedReport(), latestReport);
+            }
+
+        } catch (ParseException e) {
+            throw new BuildException("impossible to resolve dependencies:\n\t" + e, e);
+        } catch (IOException e) {
+            throw new BuildException("impossible to resolve dependencies:\n\t" + e, e);
+        }
+
+    }
+
+    private void displayDependencyUpdates(ResolveReport originalReport, ResolveReport latestReport)
{
+        log("Dependencies updates available :");
+        boolean dependencyUpdateDetected = false;
+        for (Iterator iterator = latestReport.getDependencies().iterator(); iterator.hasNext();)
{
+            IvyNode latest = (IvyNode) iterator.next();
+            for (Iterator iterator2 = originalReport.getDependencies().iterator(); iterator2.hasNext();)
{
+                IvyNode originalDependency = (IvyNode) iterator2.next();
+                if (originalDependency.getModuleId().equals(latest.getModuleId())) {
+                    if (!originalDependency.getResolvedId().getRevision().equals(latest.getResolvedId().getRevision()))
{
+                        // is this dependency a transitive dependency ? or direct dependency
+                        // (unfortunatly
+                        // .isTranstive() methods doesn't have the same meaning)
+                        boolean isTransitiveDependency = latest.getDependencyDescriptor(latest.getRoot())
== null;
+                        if ((!isTransitiveDependency) || (isTransitiveDependency &&
showTransitive)) {
+                            StringBuffer sb = new StringBuffer();
+                            sb.append("\t")//
+                                    .append(originalDependency.getResolvedId().getOrganisation())
//
+                                    .append('#')//
+                                    .append(originalDependency.getResolvedId().getName())//
+                                    .append(isTransitiveDependency ? " (transitive)" : "")
//
+                                    .append("\t")//
+                                    .append(originalDependency.getResolvedId().getRevision())//
+                                    .append(" -> ")//
+                                    .append(latest.getResolvedId().getRevision());
+                            log(sb.toString());
+                            dependencyUpdateDetected = true;
+                        }
+                    }
+
+                }
+            }
+        }
+        if (!dependencyUpdateDetected) {
+            log("\tAll dependencies are up to date");
+        }
+    }
+
+    private void displayMissingDependencyOnLatest(ResolveReport originalReport, ResolveReport
latestReport) {
+        List/* <ModuleRevisionId> */listOfMissingDependencyOnLatest = new ArrayList/*
+                                                                                    * <ModuleRevisionId
>
+                                                                                    */();
+        for (Iterator iterator = originalReport.getDependencies().iterator(); iterator.hasNext();)
{
+            IvyNode originalDependency = (IvyNode) iterator.next();
+            boolean dependencyFound = false;
+            for (Iterator iterator2 = latestReport.getDependencies().iterator(); iterator2.hasNext();)
{
+                IvyNode latest = (IvyNode) iterator2.next();
+                if (originalDependency.getModuleId().equals(latest.getModuleId())) {
+                    dependencyFound = true;
+                }
+            }
+            if (!dependencyFound) {
+                listOfMissingDependencyOnLatest.add(originalDependency.getId());
+            }
+        }
+
+        if (listOfMissingDependencyOnLatest.size() > 0) {
+            log("List of missing dependency on latest resolve :");
+            for (Iterator iterator = listOfMissingDependencyOnLatest.iterator(); iterator.hasNext();)
{
+                ModuleRevisionId moduleRevisionId = (ModuleRevisionId) iterator.next();
+                log("\t" + moduleRevisionId.toString());
+            }
+        }
+    }
+
+    private void displayNewDependencyOnLatest(ResolveReport originalReport, ResolveReport
latestReport) {
+        List/* <ModuleRevisionId> */listOfNewDependencyOnLatest = new ArrayList/* <ModuleRevisionId>
*/();
+        for (Iterator iterator = latestReport.getDependencies().iterator(); iterator.hasNext();)
{
+            IvyNode latest = (IvyNode) iterator.next();
+
+            boolean dependencyFound = false;
+            for (Iterator iterator2 = originalReport.getDependencies().iterator(); iterator2.hasNext();)
{
+                IvyNode originalDependency = (IvyNode) iterator2.next();
+                if (originalDependency.getModuleId().equals(latest.getModuleId())) {
+                    dependencyFound = true;
+                }
+            }
+            if (!dependencyFound) {
+                listOfNewDependencyOnLatest.add(latest.getId());
+            }
+        }
+        if (listOfNewDependencyOnLatest.size() > 0) {
+            log("List of new dependency on latest resolve :");
+            for (Iterator iterator = listOfNewDependencyOnLatest.iterator(); iterator.hasNext();)
{
+                ModuleRevisionId moduleRevisionId = (ModuleRevisionId) iterator.next();
+                log("\t" + moduleRevisionId.toString());
+            }
+        }
+    }
+
+    public String getRevisionToCheck() {
+        return revisionToCheck;
+    }
+
+    public void setRevisionToCheck(String revisionToCheck) {
+        this.revisionToCheck = revisionToCheck;
+    }
+
+    public boolean isDownload() {
+        return download;
+    }
+
+    public void setDownload(boolean download) {
+        this.download = download;
+    }
+
+    public boolean isShowTransitive() {
+        return showTransitive;
+    }
+
+    public void setShowTransitive(boolean showTransitive) {
+        this.showTransitive = showTransitive;
+    }
+
+}

Added: ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginUpdateChecker.java
URL: http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginUpdateChecker.java?rev=1498803&view=auto
==============================================================================
--- ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginUpdateChecker.java
(added)
+++ ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginUpdateChecker.java
Tue Jul  2 07:00:36 2013
@@ -0,0 +1,82 @@
+package org.apache.easyant.tasks;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.ParseException;
+
+import org.apache.easyant.core.EasyAntConstants;
+import org.apache.easyant.core.EasyAntMagicNames;
+import org.apache.easyant.core.report.EasyAntReport;
+import org.apache.easyant.core.report.ImportedModuleReport;
+import org.apache.easyant.core.services.PluginService;
+import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.report.ResolveReport;
+import org.apache.ivy.core.resolve.ResolveOptions;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
+
+public class PluginUpdateChecker extends AbstractEasyAntTask {
+
+    private File moduleIvy;
+    private File moduleAnt;
+    private File overrideModuleAnt;
+    private String revisionToCheck = "latest.release";
+
+    public void execute() throws BuildException {
+        PluginService pluginService = (PluginService) getProject().getReference(
+                EasyAntMagicNames.PLUGIN_SERVICE_INSTANCE);
+        if (moduleIvy == null) {
+            String moduleIvyProperty = getProject().getProperty(EasyAntMagicNames.EASYANT_FILE);
+            if (moduleIvyProperty != null) {
+                moduleIvy = new File(moduleIvyProperty);
+            } else {
+                moduleIvy = new File(getProject().getBaseDir(), EasyAntConstants.DEFAULT_BUILD_MODULE);
+            }
+            if (moduleIvy.exists() && overrideModuleAnt == null) {
+                overrideModuleAnt = new File(moduleIvy.getParent(), EasyAntConstants.DEFAULT_OVERRIDE_BUILD_FILE);
+            }
+        }
+        if (moduleAnt == null) {
+            String moduleAntProperty = getProject().getProperty(MagicNames.ANT_FILE);
+            if (moduleAntProperty != null) {
+                moduleAnt = new File(moduleAntProperty);
+            } else {
+                moduleAnt = new File(getProject().getBaseDir(), EasyAntConstants.DEFAULT_BUILD_FILE);
+            }
+        }
+        try {
+            EasyAntReport easyantReport = pluginService.generateEasyAntReport(moduleIvy,
moduleAnt, overrideModuleAnt);
+            log("Plugin updates available :");
+            for (ImportedModuleReport importedModuleReport : easyantReport.getImportedModuleReports())
{
+                checkNewRevision(importedModuleReport.getModuleRevisionId());
+            }
+        } catch (Exception e) {
+            throw new BuildException(e);
+        }
+    }
+
+    public void checkNewRevision(ModuleRevisionId moduleRevisionId) throws ParseException,
IOException {
+        ModuleRevisionId latest = ModuleRevisionId.newInstance(moduleRevisionId, revisionToCheck);
+
+        ResolveOptions resolveOptions = new ResolveOptions();
+        resolveOptions.setLog(ResolveOptions.LOG_QUIET);
+        resolveOptions.setDownload(false);
+        ResolveReport report = getEasyAntIvyInstance().getResolveEngine().resolve(latest,
resolveOptions, true);
+        String resolvedRevision = report.getModuleDescriptor().getDependencies()[0].getDependencyRevisionId()
+                .getRevision();
+        if (!resolvedRevision.equals(moduleRevisionId.getRevision())) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("\t")//
+                    .append(moduleRevisionId.getOrganisation()) //
+                    .append('#')//
+                    .append(moduleRevisionId.getName())//
+                    .append("\t")// ;
+                    .append(moduleRevisionId.getRevision())//
+                    .append(" -> ")//
+                    .append(resolvedRevision);
+            log(sb.toString());
+        }
+
+    }
+
+}

Modified: ant/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml
URL: http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml?rev=1498803&r1=1498802&r2=1498803&view=diff
==============================================================================
--- ant/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml (original)
+++ ant/easyant/core/trunk/src/main/resources/org/apache/easyant/antlib.xml Tue Jul  2 07:00:36
2013
@@ -49,6 +49,9 @@
 
     <taskdef name="plugin-report" classname="org.apache.easyant.tasks.PluginReport"/>
 
+    <taskdef name="checkdepsupdate" classname="org.apache.easyant.tasks.IvyDependencyUpdateChecker"/>
+    <taskdef name="check-plugin-updates" classname="org.apache.easyant.tasks.PluginUpdateChecker"/>
+
     
     <presetdef name="include">
         <current:import mode="include" />



Mime
View raw message