Skip to content

Commit e29debf

Browse files
committed
EDIT: The XtendLibraryHelper now checks whether the dependencies he tries to add already exits.
1 parent 8d16a56 commit e29debf

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

src/main/java/jce/codegen/WrapperGenerator.xtend

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ final class WrapperGenerator {
103103
* Checks whether the EPackage is empty or not. An empty ePackage has no classifiers and only empty subpackages.
104104
*/
105105
def private static boolean isEmpty(EPackage ePackage) {
106-
var empty = true;
106+
var empty = true
107107
for (EClassifier eClassifier : ePackage.EClassifiers) { // for every classifier
108108
empty = empty && !(eClassifier instanceof EClass) // check if is EClass
109109
}
@@ -135,4 +135,4 @@ final class WrapperGenerator {
135135
}
136136
}
137137
'''
138-
}
138+
}

src/main/java/jce/codegen/XtendLibraryHelper.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.IOException;
77
import java.nio.file.Files;
88
import java.nio.file.Path;
9+
import java.util.Arrays;
910
import java.util.LinkedList;
1011
import 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

Comments
 (0)