Bug 407656 - Build path cycle warning prevents from exporting Ant
buildfile
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/AntBuildfileExportPage.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/AntBuildfileExportPage.java
index ac25fe0..c3865e5 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/AntBuildfileExportPage.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/AntBuildfileExportPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 Richard Hoefter and others.
+ * Copyright (c) 2004, 2013 Richard Hoefter and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -25,6 +25,7 @@
import javax.xml.transform.TransformerException;
import org.eclipse.ant.internal.ui.AntUIPlugin;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -250,14 +251,30 @@
setErrorMessage(DataTransferMessages.AntBuildfileExportPage_18);
complete = false;
}
- List cyclicProjects;
try {
- cyclicProjects = getCyclicProjects(getProjects(false));
- if (cyclicProjects.size() > 0) {
- setErrorMessage(MessageFormat.format(DataTransferMessages.AntBuildfileExportPage_6,
- new String[] {ExportUtil.toString(cyclicProjects, ", ")})); //$NON-NLS-1$
- complete = false;
- }
+ List projectsWithErrors = new ArrayList();
+ List projectsWithWarnings = new ArrayList();
+ findCyclicProjects(getProjects(false), projectsWithErrors, projectsWithWarnings);
+ if (projectsWithErrors.size() > 0) {
+ String message = DataTransferMessages.AntBuildfileExportPage_cycle_error_in_projects;
+ if(projectsWithErrors.size() == 1) {
+ message = DataTransferMessages.AntBuildfileExportPage_cycle_error_in_project;
+ }
+ setErrorMessage(MessageFormat.format(
+ message,
+ new String[] { ExportUtil.toString(projectsWithErrors, ", ") })); //$NON-NLS-1$
+ complete = false;
+ } else if (projectsWithWarnings.size() > 0) {
+ String message = DataTransferMessages.AntBuildfileExportPage_cycle_warning_in_projects;
+ if(projectsWithWarnings.size() == 1) {
+ message = DataTransferMessages.AntBuildfileExportPage_cycle_warning_in_project;
+ }
+ setMessage(MessageFormat.format(
+ message,
+ new String[] { ExportUtil.toString(projectsWithWarnings, ", ") }), WARNING); //$NON-NLS-1$
+ } else {
+ setMessage(null);
+ }
} catch (CoreException e) {}
if (buildfilenameText.getText().length() == 0) {
setErrorMessage(DataTransferMessages.AntBuildfileExportPage_19);
@@ -383,25 +400,30 @@
return projects;
}
- /**
- * Returns given projects that have cyclic dependencies.
- *
- * @param javaProjects list of IJavaProject objects
- * @return set of project names
- */
- private List getCyclicProjects(Set projects) throws CoreException {
-
- List cyclicProjects = new ArrayList();
- for (Iterator iter = projects.iterator(); iter.hasNext();)
- {
- IJavaProject javaProject = (IJavaProject) iter.next();
- if (ExportUtil.hasCyclicDependency(javaProject))
- {
- cyclicProjects.add(javaProject.getProject().getName());
- }
- }
- return cyclicProjects;
- }
+ /**
+ * Splits a set of given projects into a list of projects that have cyclic
+ * dependency errors and a list of projects that have cyclic dependency
+ * warnings.
+ */
+ private void findCyclicProjects(Set projects, List errors, List warnings) throws CoreException {
+ for (Iterator iter = projects.iterator(); iter.hasNext();) {
+ IJavaProject javaProject = (IJavaProject) iter.next();
+ IMarker marker = ExportUtil.getCyclicDependencyMarker(javaProject);
+ if (marker != null) {
+ Integer severityAttr = (Integer) marker.getAttribute(IMarker.SEVERITY);
+ if (severityAttr != null) {
+ switch (severityAttr.intValue()) {
+ case IMarker.SEVERITY_ERROR:
+ errors.add(javaProject.getProject().getName());
+ break;
+ case IMarker.SEVERITY_WARNING:
+ warnings.add(javaProject.getProject().getName());
+ break;
+ }
+ }
+ }
+ }
+ }
/**
* Get list of projects which have already a buildfile that was not
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/DataTransferMessages.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/DataTransferMessages.java
index 14fd7b3..edaad52 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/DataTransferMessages.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/DataTransferMessages.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2004, 2013 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -33,7 +33,6 @@
public static String AntBuildfileExportPage_2;
public static String AntBuildfileExportPage_3;
public static String AntBuildfileExportPage_4;
- public static String AntBuildfileExportPage_6;
public static String AntNewJavaProjectPage_9;
public static String AntNewJavaProjectPage_0;
public static String AntNewJavaProjectPage_10;
@@ -71,5 +70,13 @@
public static String AntBuildfileExportPage_creating_build_files;
+ public static String AntBuildfileExportPage_cycle_error_in_project;
+
+ public static String AntBuildfileExportPage_cycle_error_in_projects;
+
+ public static String AntBuildfileExportPage_cycle_warning_in_project;
+
+ public static String AntBuildfileExportPage_cycle_warning_in_projects;
+
public static String BuildFileCreator_generating_buildfile_for;
}
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/DataTransferMessages.properties b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/DataTransferMessages.properties
index bae1934..d5b801d 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/DataTransferMessages.properties
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/DataTransferMessages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2004, 2009 IBM Corporation and others.
+# Copyright (c) 2004, 2013 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -27,8 +27,11 @@
AntBuildfileExportPage_20=JUnit output directory name is required.
AntBuildfileExportPage_3=Are you sure you want to overwrite the buildfiles for these projects?
AntBuildfileExportPage_4=Overwrite Buildfiles?
-AntBuildfileExportPage_6=A cycle was detected in the build path of project: {0}
AntBuildfileExportPage_creating_build_files=Creating Ant build files...
+AntBuildfileExportPage_cycle_error_in_project=A cycle error was detected in the build path of project {0}
+AntBuildfileExportPage_cycle_error_in_projects=A cycle error was detected in the build path of projects: {0}
+AntBuildfileExportPage_cycle_warning_in_project=A cycle warning was detected in the build path of project {0}
+AntBuildfileExportPage_cycle_warning_in_projects=A cycle warning was detected in the build path of projects: {0}
AntNewJavaProjectPage_9=Create a Java Project from an Ant Buildfile
AntNewJavaProjectPage_0=Specified buildfile does not exist
AntNewJavaProjectPage_10=Create a new Java project based on the specification of a javac task in the Ant buildfile. This does not copy the source contents to the workspace.
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/ExportUtil.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/ExportUtil.java
index 170466d..8b11f9d 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/ExportUtil.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/datatransfer/ExportUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 Richard Hoefter and others.
+ * Copyright (c) 2004, 2013 Richard Hoefter and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -315,12 +315,18 @@
}
/**
- * Check if given project has a cyclic dependency.
+ * Returns cyclic dependency marker for a given project.
*
* <p>
* See org.eclipse.jdt.core.tests.model.ClasspathTests.numberOfCycleMarkers.
+ *
+ * @param javaProject
+ * project for which cyclic dependency marker should be found
+ * @return cyclic dependency marker for a given project or <code>null</code>
+ * if there is no such marker
+ * @throws CoreException
*/
- public static boolean hasCyclicDependency(IJavaProject javaProject)
+ public static IMarker getCyclicDependencyMarker(IJavaProject javaProject)
throws CoreException {
IMarker[] markers = javaProject.getProject().findMarkers(
IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false,
@@ -331,10 +337,10 @@
.getAttribute(IJavaModelMarker.CYCLE_DETECTED);
if (cycleAttr != null && cycleAttr.equals("true")) //$NON-NLS-1$
{
- return true;
+ return marker;
}
}
- return false;
+ return null;
}
/**