Skip to content

Commit a4cbc9d

Browse files
committed
Initial commit
0 parents  commit a4cbc9d

16 files changed

+320
-0
lines changed

.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

.project

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>com.qivicon.testbuilder</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.source=1.8

META-INF/MANIFEST.MF

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: com.qivicon.testbuilder
4+
Bundle-SymbolicName: com.qivicon.testbuilder;singleton:=true
5+
Bundle-Version: 1.0.0.qualifier
6+
Bundle-Activator: com.qivicon.testbuilder.Activator
7+
Require-Bundle: org.eclipse.ui,
8+
org.eclipse.core.runtime,
9+
org.eclipse.core.resources
10+
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
11+
Automatic-Module-Name: TestBuilder
12+
Bundle-ActivationPolicy: lazy
1.14 KB
Binary file not shown.
3.4 KB
Binary file not shown.
1.92 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

build.properties

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = plugin.xml,\
4+
META-INF/,\
5+
.

plugin.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?eclipse version="3.4"?>
3+
<plugin>
4+
<extension id="qiviconbuilder" name="QIVICON Builder" point="org.eclipse.core.resources.builders">
5+
<builder>
6+
<run class="com.qivicon.testbuilder.QiviconBuilder">
7+
<parameter name="optimize" value="true" />
8+
<parameter name="comment" value="QIVICON Builder" />
9+
</run>
10+
</builder>
11+
</extension>
12+
</plugin>
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.qivicon.testbuilder;
2+
3+
import org.eclipse.jface.resource.ImageDescriptor;
4+
import org.eclipse.ui.plugin.AbstractUIPlugin;
5+
import org.osgi.framework.BundleContext;
6+
7+
/**
8+
* The activator class controls the plug-in life cycle
9+
*/
10+
public class Activator extends AbstractUIPlugin {
11+
12+
// The plug-in ID
13+
public static final String PLUGIN_ID = "TestBuilder"; //$NON-NLS-1$
14+
15+
// The shared instance
16+
private static Activator plugin;
17+
18+
/**
19+
* The constructor
20+
*/
21+
public Activator() {
22+
}
23+
24+
/*
25+
* (non-Javadoc)
26+
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
27+
*/
28+
public void start(BundleContext context) throws Exception {
29+
super.start(context);
30+
plugin = this;
31+
}
32+
33+
/*
34+
* (non-Javadoc)
35+
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
36+
*/
37+
public void stop(BundleContext context) throws Exception {
38+
plugin = null;
39+
super.stop(context);
40+
}
41+
42+
/**
43+
* Returns the shared instance
44+
*
45+
* @return the shared instance
46+
*/
47+
public static Activator getDefault() {
48+
return plugin;
49+
}
50+
51+
/**
52+
* Returns an image descriptor for the image file at the given
53+
* plug-in relative path
54+
*
55+
* @param path the path
56+
* @return the image descriptor
57+
*/
58+
public static ImageDescriptor getImageDescriptor(String path) {
59+
return imageDescriptorFromPlugin(PLUGIN_ID, path);
60+
}
61+
}
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.qivicon.testbuilder;
2+
3+
import java.io.BufferedInputStream;
4+
import java.io.File;
5+
import java.io.FileInputStream;
6+
import java.io.FileOutputStream;
7+
import java.io.IOException;
8+
import java.util.jar.JarEntry;
9+
import java.util.jar.JarOutputStream;
10+
import java.util.jar.Manifest;
11+
12+
public class JarZipper implements AutoCloseable {
13+
14+
public static int BUFFER_SIZE = 10240;
15+
16+
private JarOutputStream targetArchive;
17+
18+
public JarZipper(final File archiveFile, final File manifestFile) throws IOException {
19+
final Manifest manifest = new Manifest(new FileInputStream(manifestFile));
20+
// manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
21+
this.targetArchive = new JarOutputStream(new FileOutputStream(archiveFile), manifest);
22+
// add(new File("inputDirectory"), targetArchive);
23+
}
24+
25+
public void add(final File source) throws IOException {
26+
if (source.isDirectory()) {
27+
addDirectory(source);
28+
} else {
29+
addFile(source);
30+
}
31+
}
32+
33+
private void addDirectory(final File source) throws IOException {
34+
if (!source.isDirectory() || !source.exists()) {
35+
return;
36+
}
37+
final String directoryName = convertPath(source.getPath());
38+
final JarEntry entry = new JarEntry(directoryName);
39+
entry.setTime(source.lastModified());
40+
targetArchive.putNextEntry(entry);
41+
targetArchive.closeEntry();
42+
for (final File nestedFile : source.listFiles()) {
43+
add(nestedFile);
44+
}
45+
}
46+
47+
private void addFile(final File source) throws IOException {
48+
if (source.isDirectory() || !source.exists()) {
49+
return;
50+
}
51+
final String fileName = convertPath(source.getPath());
52+
final JarEntry entry = new JarEntry(fileName);
53+
entry.setTime(source.lastModified());
54+
targetArchive.putNextEntry(entry);
55+
try (final BufferedInputStream in = new BufferedInputStream(new FileInputStream(source))) {
56+
byte[] buffer = new byte[BUFFER_SIZE];
57+
while (true) {
58+
int count = in.read(buffer);
59+
if (count <= 0) {
60+
break;
61+
}
62+
targetArchive.write(buffer, 0, count);
63+
}
64+
targetArchive.closeEntry();
65+
}
66+
}
67+
68+
/**
69+
* To conform to ZIP standards, strip potential slash at the beginning, make sure slash is appended at the end.
70+
* @param pathName non-null path name of file or directory
71+
* @return sanitized, conforming path
72+
*/
73+
private static String convertPath(final String pathName) {
74+
String conformingName = pathName.replace("\\", "/");
75+
if (!conformingName.isEmpty()) {
76+
if (!conformingName.endsWith("/")) {
77+
conformingName += "/";
78+
}
79+
if (conformingName.startsWith("/")) {
80+
conformingName = conformingName.substring(1);
81+
}
82+
}
83+
return conformingName;
84+
}
85+
86+
@Override
87+
public void close() throws Exception {
88+
targetArchive.close();
89+
}
90+
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.qivicon.testbuilder;
2+
3+
import java.util.Map;
4+
5+
import org.eclipse.core.resources.IProject;
6+
import org.eclipse.core.resources.IResourceDelta;
7+
import org.eclipse.core.resources.IncrementalProjectBuilder;
8+
import org.eclipse.core.runtime.CoreException;
9+
import org.eclipse.core.runtime.IProgressMonitor;
10+
11+
/**
12+
* Builder for zipping compiled build artifacts of an arbitrary project into an
13+
* OSGi-compliant JAR bundle file and copy it to a well-defined location, such
14+
* as a bnd repository location of a bnd workspace.
15+
*
16+
* @see <a href=
17+
* "http://help.eclipse.org/photon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_builders.htm&cp=2_0_11_1">official
18+
* Eclipse Photon documentation about incremental builders</a>
19+
*
20+
* <a href=
21+
* "http://www.eclipse.org/articles/Article-Builders/builders.html">article
22+
* about Eclipse project builders and natures</a>
23+
*/
24+
public class QiviconBuilder extends IncrementalProjectBuilder {
25+
26+
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
27+
// kind is one of FULL_BUILD, INCREMENTAL_BUILD, AUTO_BUILD, CLEAN_BUILD
28+
if (kind == IncrementalProjectBuilder.FULL_BUILD) {
29+
fullBuild(monitor);
30+
} else {
31+
final IResourceDelta delta = getDelta(getProject());
32+
if (delta == null) {
33+
fullBuild(monitor);
34+
} else {
35+
incrementalBuild(delta, monitor);
36+
}
37+
}
38+
// TODO Return something useful
39+
return null;
40+
}
41+
42+
protected void incrementalBuild(final IResourceDelta delta, final IProgressMonitor monitor) throws CoreException {
43+
// TODO Implement me
44+
// the visitor does the work.
45+
delta.accept(new ResourceBuildDeltaVisitor());
46+
}
47+
48+
protected void fullBuild(final IProgressMonitor monitor) throws CoreException {
49+
try {
50+
// TODO Implement me
51+
getProject().accept(new ResourceBuildVisitor());
52+
} catch (CoreException e) {
53+
// TODO Comment why this does not bother us
54+
}
55+
}
56+
57+
protected void startupOnInitialize() {
58+
// add builder init logic here
59+
}
60+
61+
protected void clean(IProgressMonitor monitor) {
62+
// add builder clean logic here
63+
}
64+
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.qivicon.testbuilder;
2+
3+
import org.eclipse.core.resources.IResourceDelta;
4+
import org.eclipse.core.resources.IResourceDeltaVisitor;
5+
import org.eclipse.core.runtime.CoreException;
6+
7+
public class ResourceBuildDeltaVisitor implements IResourceDeltaVisitor {
8+
9+
@Override
10+
public boolean visit(final IResourceDelta res) throws CoreException {
11+
12+
// build the specified resource
13+
// return true to continue visiting children
14+
return true;
15+
}
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.qivicon.testbuilder;
2+
3+
import org.eclipse.core.resources.IResource;
4+
import org.eclipse.core.resources.IResourceVisitor;
5+
import org.eclipse.core.runtime.CoreException;
6+
7+
public class ResourceBuildVisitor implements IResourceVisitor {
8+
9+
@Override
10+
public boolean visit(final IResource res) throws CoreException {
11+
// build the specified resource
12+
// return true to continue visiting children
13+
return true;
14+
}
15+
}

0 commit comments

Comments
 (0)