Skip to content

Commit

Permalink
[PDE-Build] Use File to represent file-system paths instead of String
Browse files Browse the repository at this point in the history
And don't name variables that denote local files 'urls'.
  • Loading branch information
HannesWell committed Jul 26, 2024
1 parent e1b5486 commit 50bd4ba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Stream;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -84,7 +85,7 @@ public abstract class AbstractScriptGenerator implements IXMLConstants, IPDEBuil
private static PDEUIStateWrapper pdeUIState;

/** Location of the plug-ins and fragments. */
protected String[] sitePaths;
protected List<File> sitePaths;
protected String[] pluginPath;
protected BuildTimeSiteFactory siteFactory;

Expand Down Expand Up @@ -343,17 +344,14 @@ public BuildTimeSite getSite(boolean refresh) throws CoreException {
* Method getPaths. These are the paths used for the BuildTimeSite
* @return URL[]
*/
private String[] getPaths() {
private List<File> getPaths() {
if (sitePaths == null) {
if (pluginPath != null) {
sitePaths = new String[pluginPath.length + 1];
System.arraycopy(pluginPath, 0, sitePaths, 0, pluginPath.length);
sitePaths[sitePaths.length - 1] = workingDirectory;
sitePaths = Stream.concat(Arrays.stream(pluginPath), Stream.of(workingDirectory)).map(File::new).toList();
} else {
sitePaths = new String[] {workingDirectory};
sitePaths = List.of(new File(workingDirectory));
}
}

return sitePaths;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import java.util.jar.JarFile;

Expand All @@ -27,19 +28,18 @@
import org.eclipse.pde.internal.build.AbstractScriptGenerator;
import org.eclipse.pde.internal.build.IPDEBuildConstants;
import org.eclipse.pde.internal.build.PDEUIStateWrapper;
import org.eclipse.pde.internal.build.Utils;

public class BuildTimeSiteContentProvider implements IPDEBuildConstants {
private final String installedBaseURL;
private final String[] urls;
private final List<File> files;
private final PDEUIStateWrapper pdeUIState;
private BuildTimeSite site;
private boolean filterP2Base = false;

public BuildTimeSiteContentProvider(String[] urls, String installedBaseURL, PDEUIStateWrapper initialState) {
public BuildTimeSiteContentProvider(List<File> urls, String installedBaseURL, PDEUIStateWrapper initialState) {
//super(null);
this.installedBaseURL = installedBaseURL;
this.urls = urls;
this.files = urls;
this.pdeUIState = initialState;
}

Expand All @@ -52,7 +52,7 @@ public String getInstalledBaseURL() {
}

public Collection<File> getPluginPaths() {
Collection<File> pluginsToCompile = findPluginXML(Utils.asFile(urls));
Collection<File> pluginsToCompile = findPluginXML(files);
if (installedBaseURL != null) {
pluginsToCompile.addAll(Arrays.asList(PluginPathFinder.getPluginPaths(installedBaseURL, filterP2Base)));
}
Expand All @@ -64,7 +64,7 @@ public URL getURL() {
}

//For every entry, return all the children of this entry is it is named plugins, otherwise return the entry itself
private Collection<File> findPluginXML(File[] location) {
private Collection<File> findPluginXML(List<File> location) {
Collection<File> collectedElements = new ArrayList<>(10);
for (File element : location) {
File f = new File(element, DEFAULT_PLUGIN_LOCATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
Expand All @@ -39,7 +40,7 @@ public class BuildTimeSiteFactory /*extends BaseSiteFactory*/ implements IPDEBui
private boolean urlsChanged = false;

// URLs from the the site will be built
private String[] sitePaths;
private List<File> sitePaths;
private String[] eeSources;

// address of the site used as a base
Expand Down Expand Up @@ -135,28 +136,16 @@ public static void setInstalledBaseSite(String installedBaseSite) {
BuildTimeSiteFactory.installedBaseLocation = installedBaseSite;
}

public void setSitePaths(String[] urls) {
public void setSitePaths(List<File> paths) {
if (sitePaths == null) {
sitePaths = urls;
sitePaths = paths;
urlsChanged = true;
return;
}

//Check if urls are not the same than sitePaths.
int i = 0;
boolean found = true;
while (found && i < sitePaths.length) {
found = false;
for (String url : urls) {
if (sitePaths[i].equals(url)) {
found = true;
break;
}
}
i++;
}
if (!found) {
sitePaths = urls;
if (!new HashSet<>(this.sitePaths).equals(new HashSet<>(paths))) {
sitePaths = paths;
urlsChanged = true;
}
}
Expand All @@ -169,18 +158,18 @@ public void setSitePaths(String[] urls) {
private Collection<File> findFeatureXMLs() {
Collection<File> features = new ArrayList<>();
Collection<File> foundFeatures = null;
for (String sitePath : sitePaths) {
for (File sitePath : sitePaths) {
File file = new File(sitePath, Constants.FEATURE_FILENAME_DESCRIPTOR);
if (file.exists()) {
//path is a feature itself
features.add(file);
continue;
} else if (new File(sitePath, DEFAULT_FEATURE_LOCATION).exists()) {
//path is a eclipse root and contains a features subdirectory
foundFeatures = Utils.findFiles(new File(sitePath), DEFAULT_FEATURE_LOCATION, Constants.FEATURE_FILENAME_DESCRIPTOR);
foundFeatures = Utils.findFiles(sitePath, DEFAULT_FEATURE_LOCATION, Constants.FEATURE_FILENAME_DESCRIPTOR);
} else {
// treat as a flat directory containing features
foundFeatures = Utils.findFiles(new File(sitePath), ".", Constants.FEATURE_FILENAME_DESCRIPTOR); //$NON-NLS-1$
foundFeatures = Utils.findFiles(sitePath, ".", Constants.FEATURE_FILENAME_DESCRIPTOR); //$NON-NLS-1$
}
if (foundFeatures != null)
features.addAll(foundFeatures);
Expand Down

0 comments on commit 50bd4ba

Please sign in to comment.