Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew M Finkbeiner2013-11-27 00:03:27 +0000
committerRoberto E. Escobar2014-03-04 19:41:48 +0000
commitfc69b03bdebd634dbc49b247f78d76f599d763fd (patch)
tree1d2095777c12442aeceff2591a4ed9a728573b65 /plugins/org.eclipse.osee.ote.ui.builder
parent8c8dab25dd96cc9169a1b3bacfddbca7cba7cd76 (diff)
downloadorg.eclipse.osee-fc69b03bdebd634dbc49b247f78d76f599d763fd.tar.gz
org.eclipse.osee-fc69b03bdebd634dbc49b247f78d76f599d763fd.tar.xz
org.eclipse.osee-fc69b03bdebd634dbc49b247f78d76f599d763fd.zip
feature[ats_KKXWE]: Implement the OTE builder
This is the initial commit to get the OTE builder working. It also includes the rest interface changes and some environment changes so that we can disconnect from the server without killing the batch, and reconnect to the server and start getting updates again.
Diffstat (limited to 'plugins/org.eclipse.osee.ote.ui.builder')
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/.classpath7
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/.project28
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/META-INF/MANIFEST.MF18
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/build.properties5
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/plugin.xml57
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/pom.xml35
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/Activator.java50
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/ArchiveBuilder.java93
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/JarPackager.java108
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEBuilderPreferencePage.java65
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEPackagingBuilder.java174
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEPackagingNature.java81
-rw-r--r--plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/ToggleNatureHandler.java130
13 files changed, 851 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/.classpath b/plugins/org.eclipse.osee.ote.ui.builder/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/.project b/plugins/org.eclipse.osee.ote.ui.builder/.project
new file mode 100644
index 00000000000..931030f0e95
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.ote.ui.builder</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.ui.builder/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..9c687020e8b
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/META-INF/MANIFEST.MF
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: OTE Builder Plug-in (Incubation)
+Bundle-SymbolicName: org.eclipse.osee.ote.ui.builder;singleton:=true
+Bundle-Version: 0.17.0.qualifier
+Bundle-Activator: org.eclipse.osee.ote.ui.builder.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.jdt.core
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Import-Package: org.eclipse.core.resources,
+ org.eclipse.osee.framework.jdk.core.util,
+ org.eclipse.osee.framework.logging,
+ org.eclipse.osee.framework.plugin.core.server,
+ org.eclipse.osee.framework.plugin.core.util
+Bundle-Vendor: Eclipse Open System Engineering Environment
+Export-Package: org.eclipse.osee.ote.ui.builder
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/build.properties b/plugins/org.eclipse.osee.ote.ui.builder/build.properties
new file mode 100644
index 00000000000..e9863e281ea
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/plugin.xml b/plugins/org.eclipse.osee.ote.ui.builder/plugin.xml
new file mode 100644
index 00000000000..8cb6eba10bc
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/plugin.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ id="OTEPackagingBuilder"
+ name="OTE Packaging Builder"
+ point="org.eclipse.core.resources.builders">
+ <builder
+ hasNature="true">
+ <run
+ class="org.eclipse.osee.ote.ui.builder.OTEPackagingBuilder">
+ </run>
+ </builder>
+ </extension>
+ <extension
+ id="OTEPackagingNature"
+ point="org.eclipse.core.resources.natures">
+ <runtime>
+ <run
+ class="org.eclipse.osee.ote.ui.builder.OTEPackagingNature">
+ </run>
+ </runtime>
+ <builder
+ id="org.eclipse.osee.ote.ui.builder.OTEPackagingBuilder">
+ </builder>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
+ <command
+ commandId="org.eclipse.osee.ote.ui.builder.addRemoveNatureCommand"
+ label="Add/Remove OTE Packaging Nature">
+ </command>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="org.eclipse.osee.ote.ui.builder.ToggleNatureHandler"
+ id="org.eclipse.osee.ote.ui.builder.addRemoveNatureCommand"
+ name="addRemoveNatureCommand">
+ </command>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.eclipse.osee.framework.ui.skynet.OseePreferencePage"
+ class="org.eclipse.osee.ote.ui.builder.OTEBuilderPreferencePage"
+ id="org.eclipse.osee.ote.ui.builder.OTEBuilderPreferencePage"
+ name="OTE Builder">
+ </page>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/pom.xml b/plugins/org.eclipse.osee.ote.ui.builder/pom.xml
new file mode 100644
index 00000000000..509b918072c
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/pom.xml
@@ -0,0 +1,35 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.osee</groupId>
+ <artifactId>org.eclipse.osee.ote.parent</artifactId>
+ <version>0.17.0-SNAPSHOT</version>
+ <relativePath>../../plugins/org.eclipse.osee.ote.parent</relativePath>
+ </parent>
+
+ <artifactId>org.eclipse.osee.ote.ui.builder</artifactId>
+ <packaging>eclipse-plugin</packaging>
+ <name>OTE Ui (Incubation)</name>
+
+ <build>
+ <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 -->
+ <resources>
+ <resource>
+ <directory>src</directory>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ </excludes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-source-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project> \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/Activator.java b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/Activator.java
new file mode 100644
index 00000000000..a042a8a7d66
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/Activator.java
@@ -0,0 +1,50 @@
+package org.eclipse.osee.ote.ui.builder;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.osee.ote.ui.builder"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/ArchiveBuilder.java b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/ArchiveBuilder.java
new file mode 100644
index 00000000000..d7a42288b4f
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/ArchiveBuilder.java
@@ -0,0 +1,93 @@
+package org.eclipse.osee.ote.ui.builder;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * This class writes class files to a jar file. This is used as part of the OTE Builder that will package up
+ * java test classes and then ship them to a server to be executed.
+ *
+ * @author Andrew M. Finkbeiner
+ *
+ */
+class ArchiveBuilder {
+
+ private List<IPath> outputLocations;
+ private Set<IContainer> packages;
+ private File workspaceArchiveHome;
+
+ public ArchiveBuilder(File workspaceArchiveHome, List<IPath> outputLocations) {
+ this.workspaceArchiveHome = workspaceArchiveHome;
+ this.outputLocations = outputLocations;
+ this.packages = new HashSet<IContainer>();
+ }
+
+ /**
+ * Add a resources parent to be archived as a java package.
+ *
+ * @param resource
+ */
+ public void addFile(IResource resource) {
+ packages.add(resource.getParent());
+ }
+
+ /**
+ * Builds a jar file with the currently added packages.
+ */
+ public void archive() {
+ for(IContainer path:packages){
+ try {
+ IResource[] resources = path.members();
+ if(resources.length > 0){
+ String fileName = getFileName(path);
+ File archive = new File(workspaceArchiveHome, fileName + ".jar");
+ if(archive.exists()){
+ archive.delete();
+ }
+ JarPackager jarPackager = new JarPackager(getPath(path));
+ jarPackager.open(archive);
+ try{
+ for(IResource resource:resources){
+ if(resource.getFullPath().toString().endsWith(".class")){
+ jarPackager.add(resource);
+ }
+ }
+ } finally {
+ jarPackager.close();
+ }
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private String getFileName(IContainer path) {
+ String name = path.getFullPath().toString().replace(".", "").replace('/', '.');
+ return name.substring(1);
+ }
+
+ private String getPath(IContainer path){
+ String strPath = path.getFullPath().toString();
+ for(IPath sourcePath:outputLocations){
+ String source = sourcePath.toString();
+ if(strPath.startsWith(sourcePath.toString())){
+ return strPath.substring(source.length());
+ }
+ }
+ return "";
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/JarPackager.java b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/JarPackager.java
new file mode 100644
index 00000000000..fbf23f9ed26
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/JarPackager.java
@@ -0,0 +1,108 @@
+package org.eclipse.osee.ote.ui.builder;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.osee.framework.jdk.core.util.ChecksumUtil;
+
+/**
+ * Creates a jar file from a single package folder.
+ *
+ * @author Andrew M. Finkbeiner
+ *
+ */
+class JarPackager {
+
+ private JarOutputStream jos;
+ private String path;
+ private File archive;
+
+
+ JarPackager(String path){
+ this.path = path;
+ if(!this.path.endsWith("/")){
+ this.path += "/";
+ }
+ if(this.path.startsWith("/")){
+ this.path = this.path.substring(1);
+ }
+ }
+
+ /**
+ * Open the archive so that we can add resources to it.
+ *
+ * @param archive
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
+ public void open(File archive) throws FileNotFoundException, IOException {
+ this.archive = archive;
+ Manifest manifest = new Manifest();
+ manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+ jos = new JarOutputStream(new FileOutputStream(archive), manifest);
+ JarEntry entry = new JarEntry(path);
+ jos.putNextEntry(entry);
+ jos.closeEntry();
+ }
+
+ public void close() throws Exception {
+ jos.close();
+ InputStream in = null;
+ PrintStream ps = null;
+ try{
+ in = new FileInputStream(archive);
+ String diskMd5Digest = ChecksumUtil.createChecksumAsString(in, "MD5");
+ ps = new PrintStream(new FileOutputStream(new File(archive.getParentFile(), archive.getName() + ".md5")));
+ ps.print(diskMd5Digest);
+ } finally {
+ if(in != null){
+ in.close();
+ }
+ if(ps != null){
+ ps.close();
+ }
+ }
+ }
+
+ public void add(IResource resource) throws IOException {
+ File theFile = resource.getLocation().toFile();
+ if(theFile.exists()){
+ BufferedInputStream in = null;
+ try
+ {
+ String name = path + theFile.getName();
+
+ JarEntry entry = new JarEntry(name);
+ jos.putNextEntry(entry);
+ in = new BufferedInputStream(new FileInputStream(theFile));
+
+ byte[] buffer = new byte[1024];
+ while (true)
+ {
+ int count = in.read(buffer);
+ if (count == -1)
+ break;
+ jos.write(buffer, 0, count);
+ }
+ jos.closeEntry();
+ }
+ finally
+ {
+ if (in != null)
+ in.close();
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEBuilderPreferencePage.java b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEBuilderPreferencePage.java
new file mode 100644
index 00000000000..c13470a0f7f
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEBuilderPreferencePage.java
@@ -0,0 +1,65 @@
+package org.eclipse.osee.ote.ui.builder;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+public class OTEBuilderPreferencePage extends PreferencePage implements
+ IWorkbenchPreferencePage {
+
+ public static final String DO_JAR_PACKAGING = "DO_JAR_PACKAGING";
+
+ private Button oteBuilder;
+
+ public OTEBuilderPreferencePage() {
+ }
+
+ public OTEBuilderPreferencePage(String title) {
+ super(title);
+ }
+
+ public OTEBuilderPreferencePage(String title, ImageDescriptor image) {
+ super(title, image);
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ noDefaultAndApplyButton();
+ oteBuilder = new Button(parent, SWT.CHECK);
+ oteBuilder.setText("Enable the OTE Jar Builder. This will enable client disconnect and not disrupt a batch.");
+ Preferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
+ oteBuilder.setSelection(prefs.getBoolean(OTEBuilderPreferencePage.DO_JAR_PACKAGING, false));
+ oteBuilder.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Preferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
+ prefs.putBoolean(OTEBuilderPreferencePage.DO_JAR_PACKAGING, oteBuilder.getSelection());
+ try {
+ prefs.flush();
+ } catch (BackingStoreException e1) {
+ e1.printStackTrace();
+ }
+ }
+ });
+ return parent;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEPackagingBuilder.java b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEPackagingBuilder.java
new file mode 100644
index 00000000000..6c2cf0fc6bd
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEPackagingBuilder.java
@@ -0,0 +1,174 @@
+package org.eclipse.osee.ote.ui.builder;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.plugin.core.util.OseeData;
+import org.osgi.service.prefs.Preferences;
+
+public class OTEPackagingBuilder extends IncrementalProjectBuilder {
+
+ public static final String BUILDER_ID = "org.eclipse.osee.ote.ui.builder.OTEPackagingBuilder";
+
+ private static final String ROOT_FOLDER_NAME = "OTE";
+ private static final String JAR_FOLDER = "workspacejars";
+
+ public static boolean isOTEBuilderActive(){
+ if(Activator.getDefault() != null && Activator.getDefault().getPreferenceStore() != null){
+ Preferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
+ return prefs.getBoolean(OTEBuilderPreferencePage.DO_JAR_PACKAGING, false);
+ } else {
+ return false;
+ }
+ }
+
+ public static File getWorkspaceArchiveFolder(){
+ File oteFolder = OseeData.getFile(ROOT_FOLDER_NAME);
+ File workspaceArchives = new File(oteFolder, JAR_FOLDER);
+ workspaceArchives.mkdirs();
+ return workspaceArchives;
+ }
+
+ public OTEPackagingBuilder(){
+ }
+
+ class SampleDeltaVisitor implements IResourceDeltaVisitor {
+
+
+ private ArchiveBuilder builder;
+
+ public SampleDeltaVisitor(ArchiveBuilder builder) {
+ this.builder = builder;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
+ */
+ @Override
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ IResource resource = delta.getResource();
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED:
+ // handle added resource
+ checkResource(resource, builder);
+ break;
+ case IResourceDelta.REMOVED:
+ // handle removed resource
+ break;
+ case IResourceDelta.CHANGED:
+ // handle changed resource
+ checkResource(resource, builder);
+ break;
+ }
+ //return true to continue visiting children.
+ return true;
+ }
+ }
+
+ class SampleResourceVisitor implements IResourceVisitor {
+
+ private ArchiveBuilder builder;
+
+ public SampleResourceVisitor(ArchiveBuilder builder) {
+ this.builder = builder;
+ }
+
+ @Override
+ public boolean visit(IResource resource) {
+ checkResource(resource, builder);
+ //return true to continue visiting children.
+ return true;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.events.InternalBuilder#build(int,
+ * java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ @SuppressWarnings("rawtypes")
+ protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
+ try{
+ if(!isOTEBuilderActive()){
+ return null;
+ }
+ long time = System.currentTimeMillis();
+ IJavaProject javaProject = JavaCore.create(getProject());
+ if(javaProject != null){
+ File workspaceArchiveHome = getWorkspaceArchiveFolder();
+ List<IPath> outputLocations = getOutputLocations(javaProject.getOutputLocation(), javaProject.getRawClasspath());
+
+ ArchiveBuilder builder = new ArchiveBuilder(workspaceArchiveHome, outputLocations);
+
+ if (kind == FULL_BUILD) {
+ fullBuild(monitor, builder);
+ } else {
+ IResourceDelta delta = getDelta(getProject());
+ if (delta == null) {
+ fullBuild(monitor, builder);
+ } else {
+ incrementalBuild(delta, monitor, builder);
+ }
+ }
+ builder.archive();
+ }
+ long elapsed = System.currentTimeMillis() - time;
+ System.out.printf("%s,%d\n", getProject().getName(), elapsed);
+ } catch (Throwable th){
+ OseeLog.log(getClass(), Level.SEVERE, "Failed to run the OTE Packager", th);
+ th.printStackTrace();
+ }
+ return null;
+ }
+
+ private List<IPath> getOutputLocations(IPath outputLocation, IClasspathEntry[] rawClasspath) {
+ List<IPath> outputLocations = new ArrayList<IPath>();
+ outputLocations.add(outputLocation);
+ for(IClasspathEntry classpathEntry:rawClasspath){
+ if(classpathEntry.getOutputLocation() != null){
+ outputLocations.add(classpathEntry.getOutputLocation());
+ }
+ }
+ return outputLocations;
+ }
+
+ void checkResource(IResource resource, ArchiveBuilder builder) {
+ if (resource instanceof IFile && resource.getName().endsWith(".class")) {
+ builder.addFile(resource);
+ }
+ }
+
+ protected void fullBuild(final IProgressMonitor monitor, ArchiveBuilder builder) throws CoreException {
+ try {
+ getProject().accept(new SampleResourceVisitor(builder));
+ } catch (CoreException e) {
+ }
+ }
+
+ protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor, ArchiveBuilder builder) throws CoreException {
+ // the visitor does the work.
+ delta.accept(new SampleDeltaVisitor(builder));
+ }
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEPackagingNature.java b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEPackagingNature.java
new file mode 100644
index 00000000000..210a9cf3009
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/OTEPackagingNature.java
@@ -0,0 +1,81 @@
+package org.eclipse.osee.ote.ui.builder;
+
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+
+public class OTEPackagingNature implements IProjectNature {
+
+ /**
+ * ID of this project nature
+ */
+ public static final String NATURE_ID = "org.eclipse.osee.ote.ui.builder.OTEPackagingNature";
+
+ private IProject project;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#configure()
+ */
+ public void configure() throws CoreException {
+ IProjectDescription desc = project.getDescription();
+ ICommand[] commands = desc.getBuildSpec();
+
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(OTEPackagingBuilder.BUILDER_ID)) {
+ return;
+ }
+ }
+
+ ICommand[] newCommands = new ICommand[commands.length + 1];
+ System.arraycopy(commands, 0, newCommands, 0, commands.length);
+ ICommand command = desc.newCommand();
+ command.setBuilderName(OTEPackagingBuilder.BUILDER_ID);
+ newCommands[newCommands.length - 1] = command;
+ desc.setBuildSpec(newCommands);
+ project.setDescription(desc, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#deconfigure()
+ */
+ public void deconfigure() throws CoreException {
+ IProjectDescription description = getProject().getDescription();
+ ICommand[] commands = description.getBuildSpec();
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(OTEPackagingBuilder.BUILDER_ID)) {
+ ICommand[] newCommands = new ICommand[commands.length - 1];
+ System.arraycopy(commands, 0, newCommands, 0, i);
+ System.arraycopy(commands, i + 1, newCommands, i,
+ commands.length - i - 1);
+ description.setBuildSpec(newCommands);
+ project.setDescription(description, null);
+ return;
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#getProject()
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
+ */
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/ToggleNatureHandler.java b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/ToggleNatureHandler.java
new file mode 100644
index 00000000000..b1730e139d3
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.builder/src/org/eclipse/osee/ote/ui/builder/ToggleNatureHandler.java
@@ -0,0 +1,130 @@
+package org.eclipse.osee.ote.ui.builder;
+
+import java.util.Iterator;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+public class ToggleNatureHandler extends AbstractHandler {
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IStructuredSelection selection = getCurrentSelection();
+ if (selection != null && selection instanceof IStructuredSelection) {
+ for (Iterator it = ((IStructuredSelection) selection).iterator(); it.hasNext();) {
+ Object element = it.next();
+ IProject project = null;
+ if (element instanceof IProject) {
+ project = (IProject) element;
+ } else if (element instanceof IAdaptable) {
+ project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
+ }
+ if (project != null) {
+ toggleNature(project);
+ }
+ }
+ }
+ return null;
+ }
+
+ private void toggleNature(IProject project) {
+ try {
+ IProjectDescription description = project.getDescription();
+ String[] natures = description.getNatureIds();
+
+ for (int i = 0; i < natures.length; ++i) {
+ if (OTEPackagingNature.NATURE_ID.equals(natures[i])) {
+ // Remove the nature
+ String[] newNatures = new String[natures.length - 1];
+ System.arraycopy(natures, 0, newNatures, 0, i);
+ System.arraycopy(natures, i + 1, newNatures, i,
+ natures.length - i - 1);
+ description.setNatureIds(newNatures);
+ project.setDescription(description, null);
+ return;
+ }
+ }
+
+ // Add the nature
+ String[] newNatures = new String[natures.length + 1];
+ System.arraycopy(natures, 0, newNatures, 0, natures.length);
+ newNatures[natures.length] = OTEPackagingNature.NATURE_ID;
+ description.setNatureIds(newNatures);
+ project.setDescription(description, null);
+ } catch (CoreException e) {
+ }
+ }
+
+ private IStructuredSelection getCurrentSelection() {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ if (!workbench.isStarting() && !workbench.isClosing()) {
+ IWorkbenchPage page = getActivePage();
+ if (page != null) {
+ IWorkbenchPart part = page.getActivePart();
+ if (part != null) {
+ IWorkbenchSite site = part.getSite();
+ if (site != null) {
+ ISelectionProvider selectionProvider = site.getSelectionProvider();
+ if(selectionProvider != null){
+ ISelection selection = selectionProvider.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ return (IStructuredSelection) selection;
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private IWorkbenchPage getActivePage() {
+ IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ return workbenchWindow != null ? workbenchWindow.getActivePage() : null;
+ }
+
+}

Back to the top