Skip to content

Commit

Permalink
Integration of junit - closes #17
Browse files Browse the repository at this point in the history
- egradle-plugin to egradle-plugin-main
- new egradle-plugin-junit-contribution project
  all dependencies to junit are handled here
- adds itself to egradle main toolbar
- contains a junit result finder
- contains a compressor to build a single junit-result which can be
  imported...
- help updated
- version to 0.4.0.beta
  • Loading branch information
de-jcup committed Sep 19, 2016
1 parent b3c4d02 commit b973d0e
Show file tree
Hide file tree
Showing 120 changed files with 1,085 additions and 60 deletions.
11 changes: 9 additions & 2 deletions egradle-freature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="de.jcup.egradle.eclipse.feature"
label="EGradle-freature"
version="0.3.1.beta"
version="0.4.0.beta"
provider-name="Albert Tregnaghi">

<description>
Expand Down Expand Up @@ -86,7 +86,14 @@ END OF TERMS AND CONDITIONS
</url>

<plugin
id="de.jcup.egradle.eclipse.plugin"
id="de.jcup.egradle.eclipse.plugin.junit.contribution"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="de.jcup.egradle.eclipse.plugin.main"
download-size="0"
install-size="0"
version="0.0.0"
Expand Down
Binary file not shown.
13 changes: 13 additions & 0 deletions egradle-plugin-junit-contribution/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Egradle Junit contribution plugin
Bundle-SymbolicName: de.jcup.egradle.eclipse.plugin.junit.contribution;singleton:=true
Bundle-Version: 0.4.0.beta
Bundle-Activator: de.jcup.egradle.eclipse.junit.contribution.Activator
Bundle-Vendor: Albert Tregnaghi
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jdt.junit;bundle-version="3.9.0",
de.jcup.egradle.eclipse.plugin.main;bundle-version="0.4.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
10 changes: 10 additions & 0 deletions egradle-plugin-junit-contribution/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* special build.gradle variant for eclipse-plugin
*
* Divided sources into src/main/java and src/main/java-eclipse - so simple junit tests can be done inside src/test/java without any eclipse dependencies
*
*
*/
dependencies {
compile project(':egradle-plugin-main')
compile library.commons_lang
}
7 changes: 7 additions & 0 deletions egradle-plugin-junit-contribution/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source.. = src/main/java/,\
src/main/java-eclipse/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions egradle-plugin-junit-contribution/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

<extension
point="org.eclipse.ui.commands">
<command
name="Import JUnit-Testresults"
categoryId="egradle.commands.category"
id="de.jcup.egradle.eclipse.junit.contribution.commands.importTestResultCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="de.jcup.egradle.eclipse.junit.contribution.commands.importTestResultCommand"
class="de.jcup.egradle.eclipse.junit.contribution.handlers.ImportGradleJunitResultsHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="de.jcup.egradle.eclipse.junit.contribution.commands.importTestResultCommand"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+7"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:egradle.toolbars.mainToolbar?after=egradle.toolbars.refreshEclipseCommand">
<command
commandId="de.jcup.egradle.eclipse.junit.contribution.commands.importTestResultCommand"
icon="icons/importGradleTestsToEclipseView.gif"
id="egradle.toolbars.importTestResultCommand"
tooltip="Import gradle test results to junit view">
</command>
</menuContribution>
</extension>

</plugin>
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2016 Albert Tregnaghi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
*
*/
package de.jcup.egradle.eclipse.junit.contribution;

import org.eclipse.jface.resource.ImageDescriptor;
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 = "de.jcup.egradle.eclipse.plugin.junit.contribution"; //$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;
}

/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2016 Albert Tregnaghi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
*
*/
package de.jcup.egradle.eclipse.junit.contribution;

import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;

import de.jcup.egradle.eclipse.api.EGradleUtil;


public class JunitContributionUtil {

private static final String ECLIPSE_JDT_JUNIT_RESULT_VIEW = "org.eclipse.jdt.junit.ResultView";

public static void showTestRunnerViewPartInActivePage() {
try {
IWorkbenchPage page= EGradleUtil.getActivePage();
if (page == null){
return;
}
IViewPart view = page.findView(ECLIPSE_JDT_JUNIT_RESULT_VIEW);
if (view == null) {
/* create and show the result view if it isn't created yet.*/
page.showView(ECLIPSE_JDT_JUNIT_RESULT_VIEW, null, IWorkbenchPage.VIEW_VISIBLE);
}
} catch (PartInitException pie) {
EGradleUtil.log(pie);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,21 @@
* and limitations under the License.
*
*/
package de.jcup.egradle.eclipse.console;
package de.jcup.egradle.eclipse.junit.contribution.handlers;

import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import de.jcup.egradle.core.process.ProcessOutputHandler;
public class ImportGradleJunitResultsHandler extends AbstractHandler {

public class EGradleConsoleProcessOutputHandler implements ProcessOutputHandler{

private MessageConsoleStream messageStream;

public EGradleConsoleProcessOutputHandler(){
this.messageStream = EGradleConsoleFactory.INSTANCE.getConsole().newMessageStream();
/* always UTF-8 encoding*/
messageStream.setEncoding("UTF-8");
}

@Override
public void output(String line) {
messageStream.println(line);
public Object execute(ExecutionEvent event) throws ExecutionException {
ImportGradleJunitResultsJob job = new ImportGradleJunitResultsJob("Import gradle junit results");
job.schedule();
return null;

}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright 2016 Albert Tregnaghi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
*
*/
package de.jcup.egradle.eclipse.junit.contribution.handlers;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.junit.JUnitCore;
import org.eclipse.swt.widgets.Display;
import org.w3c.dom.Document;

import de.jcup.egradle.core.api.XMLWriter;
import de.jcup.egradle.eclipse.api.EGradleUtil;
import de.jcup.egradle.eclipse.junit.contribution.Activator;
import de.jcup.egradle.eclipse.junit.contribution.JunitContributionUtil;
import de.jcup.egradle.junit.JUnitResultFilesFinder;
import de.jcup.egradle.junit.JUnitResultsCompressor;

public class ImportGradleJunitResultsJob extends Job {

XMLWriter writer = new XMLWriter();
JUnitResultsCompressor compressor = new JUnitResultsCompressor();
JUnitResultFilesFinder finder = new JUnitResultFilesFinder();

public ImportGradleJunitResultsJob(String name) {
super(name);
}

@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("Import junit results from gradle", 100);
File tempFile = new File(System.getProperty("user.home")+"/.egradle/TEST-egradle-all-testresults.tmp.xml");
try {
/* remove old temp file if existing */
if (tempFile.exists()) {
if (!tempFile.delete()) {
throw new IOException("Cannot delete temporary file for gradle results!");
}
}

/* fetch files*/
monitor.setTaskName("Fetching gradle junit result files");
File rootFolder = EGradleUtil.getRootProjectFolder();

Collection<File> files = finder.findTestFilesInRootProjectFolder(rootFolder);
List<InputStream> streams = new ArrayList<>();
for (File file : files) {
streams.add(new FileInputStream(file));
}
monitor.worked(40);

/* compress*/
monitor.setTaskName("Compress results for import");
Document singleDoc = compressor.compress(streams);
monitor.worked(60);

/* write to file*/
monitor.setTaskName("Create temp file");
tempFile.getParentFile().mkdirs();
if (!tempFile.createNewFile()){
throw new IOException("Cannot create empty temp file!");
}
writer.writeDocumentToFile(singleDoc, tempFile);
monitor.worked(80);

/* show inside junit viewer*/
monitor.setTaskName("Load into junit view");

// JUnitCore.importTestRunSession(tempFile.toURI().toURL().toExternalForm(), monitor);
JUnitCore.importTestRunSession(tempFile);
monitor.worked(90);

monitor.setTaskName("Open test results in view");
Display.getDefault().asyncExec(new Runnable() {

@Override
public void run() {
JunitContributionUtil.showTestRunnerViewPartInActivePage();
monitor.worked(100);
}
});
} catch (Exception e) {
return new Status(Status.ERROR, Activator.PLUGIN_ID, "Cannot import junit results", e);
}
return Status.OK_STATUS;
}

}
Loading

0 comments on commit b973d0e

Please sign in to comment.