Skip to content

Commit

Permalink
Fixed Examples build.properties
Browse files Browse the repository at this point in the history
The build.properties src.inlucde entry had more entries then necessary.
This was cleaned

Furthermore several warnings and issues reported by sonar have been
fixed in the example creation wizard.
  • Loading branch information
azoitl committed Dec 14, 2024
1 parent 85955ec commit df1764f
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 100 deletions.
9 changes: 1 addition & 8 deletions org.eclipse.gef.examples.digraph1/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,4 @@ bin.includes = META-INF/,\
plugin.xml,\
plugin.properties,\
icons/
src.includes = META-INF/,\
build.properties,\
icons/,\
plugin.properties,\
plugin.xml,\
.classpath,\
.project,\
src/
src.includes = icons/
9 changes: 1 addition & 8 deletions org.eclipse.gef.examples.digraph2/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,4 @@ bin.includes = META-INF/,\
plugin.xml,\
plugin.properties,\
icons/
src.includes = META-INF/,\
build.properties,\
icons/,\
plugin.properties,\
plugin.xml,\
.classpath,\
.project,\
src/
src.includes = icons/
5 changes: 1 addition & 4 deletions org.eclipse.gef.examples.flow/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@ bin.includes = about.*,\
META-INF/,\
plugin.properties
source.. = src/
src.includes = META-INF/,\
plugin.properties,\
plugin.xml,\
view.gif,\
src.includes = view.gif,\
about.html
7 changes: 2 additions & 5 deletions org.eclipse.gef.examples.logic/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@ bin.includes = about.html,\
logic.gif,\
META-INF/
source.. = src/
src.includes = META-INF/,\
about.html,\
logic.gif,\
plugin.properties,\
plugin.xml
src.includes = about.html,\
logic.gif
5 changes: 1 addition & 4 deletions org.eclipse.gef.examples.shapes/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ bin.includes = plugin.xml,\
META-INF/,\
plugin.properties,\
fragment.e4xmi
src.includes = META-INF/,\
about.html,\
plugin.properties,\
plugin.xml,\
src.includes = about.html,\
shapes.gif

5 changes: 1 addition & 4 deletions org.eclipse.gef.examples.text/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ bin.includes = plugin.xml,\
about.*,\
META-INF/,\
plugin.properties
src.includes = META-INF/,\
about.html,\
plugin.properties,\
plugin.xml,\
src.includes = about.html,\
text.gif

Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
package org.eclipse.gef.examples.ui.pde.internal.wizards;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
Expand All @@ -41,7 +41,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
Expand All @@ -63,7 +63,7 @@
*
* @see Wizard
*/
abstract public class ProjectUnzipperNewWizard extends Wizard implements INewWizard, IExecutableExtension {
public abstract class ProjectUnzipperNewWizard extends Wizard implements INewWizard, IExecutableExtension {

/**
* Java Nature
Expand All @@ -84,32 +84,32 @@ abstract public class ProjectUnzipperNewWizard extends Wizard implements INewWiz
/**
* The name of the project creation page
*/
private String pageName;
private final String pageName;

/**
* The title of the project creation page
*/
private String pageTitle;
private final String pageTitle;

/**
* The description of the project creation page
*/
private String pageDescription;
private final String pageDescription;

/**
* The name of the project in the project creation page
*/
private String pageProjectName;
private final String pageProjectName;

/**
* The list of paths pointing to the location of the project archives
*/
private URL[] projectZipURL;
private final URL[] projectZipURL;

/**
* The list of formats to be applied to the user supplied name
*/
private String[] nameFormats;
private final String[] nameFormats;

/**
* The configuration element associated with this new project wizard
Expand All @@ -126,7 +126,7 @@ abstract public class ProjectUnzipperNewWizard extends Wizard implements INewWiz
* @param projectZipURLIn The URL pointing to the location of the project
* archive
*/
public ProjectUnzipperNewWizard(String pageNameIn, String pageTitleIn, String pageDescriptionIn,
protected ProjectUnzipperNewWizard(String pageNameIn, String pageTitleIn, String pageDescriptionIn,
String pageProjectNameIn, URL projectZipURLIn) {
this(pageNameIn, pageTitleIn, pageDescriptionIn, pageProjectNameIn, new URL[] { projectZipURLIn },
new String[] { "{0}" }); //$NON-NLS-1$
Expand All @@ -141,7 +141,7 @@ public ProjectUnzipperNewWizard(String pageNameIn, String pageTitleIn, String pa
* @param pageProjectNameIn The project name in the project creation page
* @param projectZipURLListIn The list of URL pointing to the location of the
* project archives
* @param formatsIn The list of formats to be applied to the user
* @param nameFormatsIn The list of formats to be applied to the user
* supplied name. The {@link java.text.MessageFormat}
* class should be consulted to understand
* substitutions. The "{0}" substitution
Expand All @@ -150,14 +150,8 @@ public ProjectUnzipperNewWizard(String pageNameIn, String pageTitleIn, String pa
* which will completely ignore the user supplied
* name.
*/
public ProjectUnzipperNewWizard(String pageNameIn, String pageTitleIn, String pageDescriptionIn,
protected ProjectUnzipperNewWizard(String pageNameIn, String pageTitleIn, String pageDescriptionIn,
String pageProjectNameIn, URL[] projectZipURLListIn, String[] nameFormatsIn) {
super();

// assert projectZipURLListIn.length > 0;
// assert nameFormatsIn.length > 0;
// assert projectZipURLListIn.length == nameFormatsIn.length;

pageName = pageNameIn;
pageTitle = pageTitleIn;
pageDescription = pageDescriptionIn;
Expand Down Expand Up @@ -191,7 +185,7 @@ public void execute(IProgressMonitor monitor) throws InterruptedException {

for (int i = 0; i < nameFormats.length; i++) {
String projectName = MessageFormat.format(nameFormats[i],
new Object[] { wizardNewProjectCreationPage.getProjectName() });
wizardNewProjectCreationPage.getProjectName());
String projectFolder = projectPath.toOSString() + File.separator + projectName;
File projectFolderFile = new File(projectFolder);

Expand All @@ -208,7 +202,7 @@ public void execute(IProgressMonitor monitor) throws InterruptedException {
* Copy plug-in project code
*/
extractProject(projectFolderFile, getProjectZipURL()[i],
new SubProgressMonitor(monitor, 100));
SubMonitor.convert(monitor, 100));

if (monitor.isCanceled()) {
throw new InterruptedException();
Expand Down Expand Up @@ -275,15 +269,10 @@ public void execute(IProgressMonitor monitor) throws InterruptedException {
* @param projectFolderFile The folder where to unzip the project archive
* @param monitor Monitor to display progress and/or cancel operation
* @throws IOException
* @throws IOException
* @throws InterruptedException
* @throws FileNotFoundException
*
* @throws FileNotFoundException
* @throws InterruptedException
*/
private void extractProject(File projectFolderFile, URL url, IProgressMonitor monitor)
throws FileNotFoundException, IOException, InterruptedException {
private static void extractProject(File projectFolderFile, URL url, IProgressMonitor monitor)
throws IOException, InterruptedException {

/*
* Get project archive
Expand All @@ -295,17 +284,14 @@ private void extractProject(File projectFolderFile, URL url, IProgressMonitor mo
/*
* Walk each element and unzip
*/
ZipFile zipFile = new ZipFile(urlZipLocal.getPath());

try {
try (ZipFile zipFile = new ZipFile(urlZipLocal.getPath())) {
/*
* Allow for a hundred work units
*/
monitor.beginTask(Messages.monitor_unzippingProject, zipFile.size());

unzip(zipFile, projectFolderFile, monitor);
} finally {
zipFile.close();
monitor.done();
}
}
Expand All @@ -317,36 +303,33 @@ private void extractProject(File projectFolderFile, URL url, IProgressMonitor mo
* @param projectFolderFile The folder where to unzip the project archive
* @param monitor Monitor to display progress and/or cancel operation
* @throws IOException
* @throws FileNotFoundException
* @throws InterruptedException
*/
private void unzip(ZipFile zipFile, File projectFolderFile, IProgressMonitor monitor)
throws IOException, FileNotFoundException, InterruptedException {
private static void unzip(ZipFile zipFile, File projectFolderFile, IProgressMonitor monitor)
throws IOException, InterruptedException {

Enumeration e = zipFile.entries();
Enumeration<? extends ZipEntry> e = zipFile.entries();

while (e.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) e.nextElement();
ZipEntry zipEntry = e.nextElement();
File file = new File(projectFolderFile, zipEntry.getName());

if (false == zipEntry.isDirectory()) {
if (!zipEntry.isDirectory()) {

/*
* Copy files (and make sure parent directory exist)
*/
File parentFile = file.getParentFile();
if (null != parentFile && false == parentFile.exists()) {
if (null != parentFile && !parentFile.exists()) {
parentFile.mkdirs();
}

Path path = new Path(file.getPath());
if (path.getFileExtension().equals("java")) { //$NON-NLS-1$
InputStreamReader is = null;
OutputStreamWriter os = null;

try {
is = new InputStreamReader(zipFile.getInputStream(zipEntry), "ISO-8859-1"); //$NON-NLS-1$
os = new OutputStreamWriter(new FileOutputStream(file), ResourcesPlugin.getEncoding());
try (InputStreamReader is = new InputStreamReader(zipFile.getInputStream(zipEntry),
StandardCharsets.ISO_8859_1);
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file),
ResourcesPlugin.getEncoding());) {
char[] buffer = new char[102400];
while (true) {
int len = is.read(buffer);
Expand All @@ -355,22 +338,10 @@ private void unzip(ZipFile zipFile, File projectFolderFile, IProgressMonitor mon
}
os.write(buffer, 0, len);
}
} finally {
if (null != is) {
is.close();
}
if (null != os) {
os.close();
}
}
} else {
InputStream is = null;
OutputStream os = null;

try {
is = zipFile.getInputStream(zipEntry);
os = new FileOutputStream(file);

try (InputStream is = zipFile.getInputStream(zipEntry);
OutputStream os = new FileOutputStream(file);) {
byte[] buffer = new byte[102400];
while (true) {
int len = is.read(buffer);
Expand All @@ -379,13 +350,6 @@ private void unzip(ZipFile zipFile, File projectFolderFile, IProgressMonitor mon
}
os.write(buffer, 0, len);
}
} finally {
if (null != is) {
is.close();
}
if (null != os) {
os.close();
}
}
}
}
Expand All @@ -405,7 +369,7 @@ private void unzip(ZipFile zipFile, File projectFolderFile, IProgressMonitor mon
* @param projectName New name for the project
* @throws CoreException
*/
private void renameProject(IProject project, String projectName) throws CoreException {
private static void renameProject(IProject project, String projectName) throws CoreException {
IProjectDescription description = project.getDescription();
description.setName(projectName);
project.move(description, IResource.FORCE | IResource.SHALLOW, null);
Expand Down
1 change: 0 additions & 1 deletion org.eclipse.zest.examples/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
</accessrules>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="icons"/>
<classpathentry kind="output" path="bin"/>
</classpath>

0 comments on commit df1764f

Please sign in to comment.