66import java .io .IOException ;
77import java .nio .file .Files ;
88import java .nio .file .Path ;
9+ import java .util .Arrays ;
910import java .util .LinkedList ;
1011import java .util .List ;
1112
@@ -44,7 +45,7 @@ private XtendLibraryHelper() {
4445
4546 /**
4647 * Adds the Xtend dependencies to a project and creates the xtend-gen source folder.
47- * @param javaProject is the {@link IJavaProject } instance of the project.
48+ * @param project is the {@link IProject } instance of the project.
4849 */
4950 public static void addXtendLibs (IProject project ) {
5051 logger .info ("Adding Xtend dependencies..." );
@@ -62,7 +63,12 @@ private static void addBuildProperty(IProject project) {
6263 IPluginModelBase base = PluginRegistry .findModel (project );
6364 IBuildModel buildModel = PluginRegistry .createBuildModel (base );
6465 IBuildEntry entry = buildModel .getBuild ().getEntry ("source.." );
65- entry .addToken (XTEND + SLASH ); // TODO (MEDIUM) check if duplicate
66+ String token = XTEND + SLASH ;
67+ if (entry .contains (token )) {
68+ logger .warn ("build.properties already contains " + token );
69+ } else {
70+ entry .addToken (token );
71+ }
6672 if (buildModel instanceof IEditableModel ) { // if saveable
6773 ((IEditableModel ) buildModel ).save (); // save changes
6874 }
@@ -79,11 +85,15 @@ private static void addClasspathEntry(IProject project) {
7985 IJavaProject javaProject = JavaCore .create (project );
8086 try {
8187 IClasspathEntry [] entries = javaProject .getRawClasspath ();
82- IClasspathEntry [] newEntries = new IClasspathEntry [entries .length + 1 ];
83- System .arraycopy (entries , 0 , newEntries , 0 , entries .length );
8488 String xtendDirectory = SLASH + javaProject .getElementName () + SLASH + XTEND ;
85- newEntries [entries .length ] = JavaCore .newSourceEntry (new org .eclipse .core .runtime .Path (xtendDirectory ));
86- javaProject .setRawClasspath (newEntries , new NullProgressMonitor ()); // TODO (MEDIUM) check if duplicate
89+ if (Arrays .asList (entries ).contains (xtendDirectory )) {
90+ logger .warn (".classpath already contains " + xtendDirectory );
91+ } else {
92+ IClasspathEntry [] newEntries = new IClasspathEntry [entries .length + 1 ];
93+ System .arraycopy (entries , 0 , newEntries , 0 , entries .length );
94+ newEntries [entries .length ] = JavaCore .newSourceEntry (new org .eclipse .core .runtime .Path (xtendDirectory ));
95+ javaProject .setRawClasspath (newEntries , new NullProgressMonitor ());
96+ }
8797 } catch (JavaModelException exception ) {
8898 logger .error (exception );
8999 }
@@ -106,6 +116,19 @@ private static void addManifestEntries(IProject project) {
106116 }
107117 }
108118
119+ /**
120+ * Adds new entry to list if there is no existing entry in the list that conatins the new entry.
121+ */
122+ private static void addTo (String newEntry , List <String > manifest ) {
123+ for (String existingEntry : manifest ) {
124+ if (existingEntry .contains (newEntry )) {
125+ logger .info ("Manifest already contains " + newEntry );
126+ return ;
127+ }
128+ }
129+ manifest .add (" " + newEntry + "," );
130+ }
131+
109132 /**
110133 * Creates the binary file folder for Xtend. This is the xtend-bin folder.
111134 */
@@ -128,12 +151,12 @@ private static void createXtendFolder(IProject project) {
128151 private static List <String > edit (List <String > manifest ) {
129152 List <String > newManifest = new LinkedList <String >();
130153 for (String line : manifest ) {
131- newManifest .add (line ); // TODO (MEDIUM) check if duplicate
154+ newManifest .add (line );
132155 if (line .contains ("Require-Bundle:" )) {
133- newManifest . add ( " com.google.guava," );
134- newManifest . add ( " org.eclipse.xtext.xbase.lib," );
135- newManifest . add ( " org.eclipse.xtend.lib," );
136- newManifest . add ( " org.eclipse.xtend.lib.macro," );
156+ addTo ( " com.google.guava" , manifest );
157+ addTo ( " org.eclipse.xtext.xbase.lib" , manifest );
158+ addTo ( " org.eclipse.xtend.lib" , manifest );
159+ addTo ( " org.eclipse.xtend.lib.macro" , manifest );
137160 }
138161 }
139162 return newManifest ;
0 commit comments