Commit fe469887 authored by Omar ALQAWASMEH's avatar Omar ALQAWASMEH
Browse files

GUI with respect to latest changes

parent b838b7a3
Loading
Loading
Loading
Loading
+43 −1
Original line number Diff line number Diff line
@@ -170,6 +170,12 @@
			<version>1.4.5.519</version>
		</dependency>

		<dependency>
			<groupId>org.openjfx</groupId>
			<artifactId>javafx-controls</artifactId>
			<version>11</version>
		</dependency>

	</dependencies>

	<build>
@@ -247,5 +253,41 @@
				</configuration>
			</plugin>
		</plugins>
		<pluginManagement>
			<plugins>
				<!--This plugin's configuration is used to store Eclipse m2e settings 
					only. It has no influence on the Maven build itself. -->
				<plugin>
					<groupId>org.eclipse.m2e</groupId>
					<artifactId>lifecycle-mapping</artifactId>
					<version>1.0.0</version>
					<configuration>
						<lifecycleMappingMetadata>
							<pluginExecutions>
								<pluginExecution>
									<pluginExecutionFilter>
										<groupId>
											org.apache.maven.plugins
										</groupId>
										<artifactId>
											maven-assembly-plugin
										</artifactId>
										<versionRange>
											[3.2.0,)
										</versionRange>
										<goals>
											<goal>single</goal>
										</goals>
									</pluginExecutionFilter>
									<action>
										<ignore></ignore>
									</action>
								</pluginExecution>
							</pluginExecutions>
						</lifecycleMappingMetadata>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>

report_output.xml

0 → 100644
+2 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<testsuites name="SAREF pipeline" tests="0" failures="0" errors="0"/>
+115 −0
Original line number Diff line number Diff line
/**
 * 
 */
package fr.emse.gitlab.saref;

import javax.swing.JComponent;
import javax.swing.JTextArea;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.LoggingEvent;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.log4j.spi.ErrorCode;

/**
 * @author Omar Qawasmeh
 * 
 * @organization Ecole des Mines de Saint Etienne
 */
/*
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (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.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * 
 * The Original Code is 'JSignPdf, a free application for PDF signing'.
 * 
 * The Initial Developer of the Original Code is Josef Cacek. Portions created
 * by Josef Cacek are Copyright (C) Josef Cacek. All Rights Reserved.
 * 
 * Contributor(s): Josef Cacek.
 * 
 * Alternatively, the contents of this file may be used under the terms of the
 * GNU Lesser General Public License, version 2.1 (the "LGPL License"), in which
 * case the provisions of LGPL License are applicable instead of those above. If
 * you wish to allow use of your version of this file only under the terms of
 * the LGPL License and not to allow others to use your version of this file
 * under the MPL, indicate your decision by deleting the provisions above and
 * replace them with the notice and other provisions required by the LGPL
 * License. If you do not delete the provisions above, a recipient may use your
 * version of this file under either the MPL or the LGPL License.
 */

public class JTextAreaAppender extends AppenderSkeleton {
	String NEW_LINE = System.getProperty("line.separator");
	private JTextArea jTextArea;

	/**
	 * Constructor.
	 * 
	 * @param jTextArea
	 */
	public JTextAreaAppender(final JTextArea jTextArea) {
		if (jTextArea == null) {
			throw new IllegalArgumentException("JTextArea has to be not-null.");
		}
		this.jTextArea = jTextArea;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.log4j.Appender#close()
	 */
	public void close() {
		jTextArea = null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.log4j.Appender#requiresLayout()
	 */
	public boolean requiresLayout() {
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
	 */

//	  protected void append(LoggingEvent event) 
//	    {
//	        if(event.getLevel().equals(Level.INFO)){
//	        jTextA.append(event.getMessage().toString());
//	        }
//	    }
	@Override
	protected void append(LoggingEvent event) {
		if (layout == null) {
			errorHandler.error("No layout for appender " + name, null, ErrorCode.MISSING_LAYOUT);
			return;
		}
		final String message = layout.format(event);
		jTextArea.append(message);

		// TODO do we need this code
		if (layout.ignoresThrowable()) {
			for (String throwableRow : ArrayUtils.nullToEmpty(event.getThrowableStrRep())) {
				jTextArea.append(throwableRow + NEW_LINE);
			}
		}
		// scroll TextArea
		jTextArea.setCaretPosition(jTextArea.getText().length());
	}

}
+362 −90
Original line number Diff line number Diff line
@@ -2,7 +2,12 @@ package fr.emse.gitlab.saref;

import static fr.emse.gitlab.saref.CMDConfigurations.*;

import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -24,6 +29,17 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
@@ -97,7 +113,6 @@ public class Main {
	private static Dataset dataset;
	private static Var VAR_TEST_SUITES = VarUtils.allocVar("testsuites");


	static boolean remoteOnly;
	static boolean ignoreGit;
	static boolean includeMaster;
@@ -106,11 +121,25 @@ public class Main {
	static boolean ignoreExamples;
	static boolean verbose;

	/* added to handle the GUI */
	static boolean fileSelected = false;

	private static JTextArea txtConsole = new JTextArea("Select a directory to start\n");
	private static JFrame frame = new JFrame();
	private static JPanel functionalitiesPanel = new JPanel(new GridLayout(0, 4));
	private static JPanel infoPanel = new JPanel();
	private static JPanel textAreaPanel = new JPanel();
	public static boolean isTheConsoleActive = true;

	public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException, JAXBException,
			ParseException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException,
			CheckoutConflictException, GitAPIException {
		if (isTheConsoleActive == true) {

	public static void main(String[] args)
			throws IOException, InterruptedException, URISyntaxException, JAXBException, ParseException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, CheckoutConflictException, GitAPIException {
			openConsole(); // open console
		}

		else {
			CommandLine cl = CMDConfigurations.parseArguments(args);
			if (cl.getOptions().length == 0 || cl.hasOption(ARG_HELP)) {
				CMDConfigurations.displayHelp();
@@ -140,7 +169,8 @@ public class Main {

			Repositories repositories;
			try {
			repositories = new ReadRepositories("Fetching required repositories").readRepositories(directory, remoteOnly, ignoreGit, includeMaster);
				repositories = new ReadRepositories("Fetching required repositories").readRepositories(directory,
						remoteOnly, ignoreGit, includeMaster);
			} catch (Exception ex) {
				reportAndExit(-1);
				return;
@@ -160,10 +190,10 @@ public class Main {
			new CheckConfig().doJob(dataset, ignoreExamples);

			if (generateSite) {
			new GeneratePortal("Generate static files for the portal", streamManager).doJob(dataset, directory, verbose, ignoreExamples, ignoreTerms);
				new GeneratePortal("Generate static files for the portal", streamManager).doJob(dataset, directory,
						verbose, ignoreExamples, ignoreTerms);
			}


			if (repositories.getDefaultRepository() != null && !ignoreGit) {
				Repository repository = repositories.getDefaultRepository();
				resetCheckout(repository);
@@ -175,6 +205,8 @@ public class Main {
			testSuites.clean();

			reportAndExit((int) -Math.signum(testSuites.getErrors() + testSuites.getFailures()));

		}
	}

	private static void setLogAppenders() throws IOException {
@@ -188,6 +220,244 @@ public class Main {
		loggerBase.addAppender(appender);
	}

	private static boolean openConsole() throws IOException, InterruptedException, URISyntaxException, JAXBException,
			ParseException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException,
			CheckoutConflictException, GitAPIException {
		setGUIAppenders();

//LOG.info("Select a directory to start");
//		JFrame.setDefaultLookAndFeelDecorated(true);

		frame = new JFrame("Saref-Pipeline tests");
		frame.setBounds(100, 100, 800, 400);
		SwingUtilities.updateComponentTreeUI(frame);

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JLabel lblWelcomeToSarefpipeline = new JLabel("SAREF ontologies pipeline tests");
		infoPanel.add(lblWelcomeToSarefpipeline);

		frame.getContentPane().add(functionalitiesPanel, BorderLayout.SOUTH);

//JLabel argsLbl = new JLabel("Please choose among the arguments:");
//functionalitiesPanel.add(argsLbl);
		JLabel lbl=new JLabel("The list of arguments:");
		functionalitiesPanel.add(lbl);
		
		JLabel emptylbl1=new JLabel();
		functionalitiesPanel.add(emptylbl1);

		JLabel emptylbl2=new JLabel();
		functionalitiesPanel.add(emptylbl2);

		JLabel emptylbl3=new JLabel();
		functionalitiesPanel.add(emptylbl3);

		
		JCheckBox remoteOnly_checkBox = new JCheckBox("Remote-only");
		remoteOnly_checkBox.setToolTipText("Do not check the directory itself.\n"
				+ " Only consider the repositories listed in the `.saref-repositories.yml` document.\n"
				+ " Used to generate the website for several extensions.");
		functionalitiesPanel.add(remoteOnly_checkBox);
		
		JCheckBox ignoreGit_checkBox = new JCheckBox("No-git");
		ignoreGit_checkBox.setToolTipText("Only check the current state of the repository");
		functionalitiesPanel.add(ignoreGit_checkBox);
		

		JCheckBox includeMaster_checkBox = new JCheckBox("Include master");
		includeMaster_checkBox.setToolTipText("Check the master branches of the remote repositories listed in the `.saref-repositories.yml` document");
		functionalitiesPanel.add(includeMaster_checkBox);

		JCheckBox generateSite_checkBox = new JCheckBox("Don't generate site");
		generateSite_checkBox.setToolTipText("Do not generate the static website");
		functionalitiesPanel.add(generateSite_checkBox);

		JCheckBox ignoreExamples_checkBox = new JCheckBox("Ignore examples");
		ignoreExamples_checkBox.setToolTipText("Only check the SAREF extension ontology. Ignore the examples");
		functionalitiesPanel.add(ignoreExamples_checkBox);

		JCheckBox verbose_checkBox = new JCheckBox("Verbose");
		verbose_checkBox.setToolTipText("Use verbose mode.\n"
				+ "(For example, use SPARQL-Generate in --debug-template mode when generating the documentation)");
		functionalitiesPanel.add(verbose_checkBox);

		JCheckBox ignoreTerms_checkBox = new JCheckBox("Ignore terms");
		ignoreTerms_checkBox.setToolTipText("Do not generate the website for terms");
		functionalitiesPanel.add(ignoreTerms_checkBox);
		
		
		JLabel emptylbl4=new JLabel();
		functionalitiesPanel.add(emptylbl4);

		JLabel emptylbl5=new JLabel();
		functionalitiesPanel.add(emptylbl5);

//		JButton startBtn = new JButton("Start the pipeline");
		
		
		JButton startBtn = new JButton("Start the pipeline");

		JButton fileChooserBtn = new JButton("Choose a directory");
		fileChooserBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JFileChooser fileChooser = new JFileChooser();
				fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				int option = fileChooser.showOpenDialog(frame);
				if (option == JFileChooser.APPROVE_OPTION) {
					directory = fileChooser.getSelectedFile();

//			directory = new File(dirName).getCanonicalFile();

					fileSelected = true;
					startBtn.setEnabled(true);
				} else {
					System.out.println("Open command canceled");
				}

			}

		});
		functionalitiesPanel.add(fileChooserBtn);

		startBtn.setEnabled(false);
		
		
		
		startBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				if (fileSelected == true) {
					startBtn.setEnabled(true);
					if (!remoteOnly_checkBox.isSelected() && !ignoreGit_checkBox.isSelected()
							&& !includeMaster_checkBox.isSelected() && !generateSite_checkBox.isSelected()
							&& !ignoreExamples_checkBox.isSelected() && !verbose_checkBox.isSelected()) {

						LOG.error("Please choose among the different options");
						return;
					}

					remoteOnly = remoteOnly_checkBox.isSelected();
					ignoreGit = ignoreGit_checkBox.isSelected();
					includeMaster = includeMaster_checkBox.isSelected();
					generateSite = !generateSite_checkBox.isSelected();
					ignoreExamples = ignoreExamples_checkBox.isSelected();
					ignoreTerms = ignoreTerms_checkBox.isSelected();
					verbose = verbose_checkBox.isSelected();
					try {

						setLogAppenders();
						prepareDirectory();
						streamManager = initializeStreamManager();
						dataset = createFreshDataset();
					} catch (Exception e) {
						// TODO: handle exception
					}

					LOG.info("Starting pipeline in " + directory);

					Repositories repositories;
					try {
						repositories = new ReadRepositories("Fetching required repositories")
								.readRepositories(directory, remoteOnly, ignoreGit, includeMaster);
					} catch (Exception ex) {
						reportAndExit(-1);
						return;
					}

					if (repositories.getDefaultRepository() != null) {
						Repository repository = repositories.getDefaultRepository();
						boolean checkExamples = !ignoreExamples;
						testRepository(repository, checkExamples);
					}
					for (Repository repository : repositories.getNamedRepositories()) {
						boolean checkExamples = !ignoreExamples && remoteOnly;
						testRepository(repository, checkExamples);
					}

					checkOWLProfile();
					new CheckConfig().doJob(dataset, ignoreExamples);

					if (generateSite) {
						try {
							new GeneratePortal("Generate static files for the portal", streamManager).doJob(dataset,
									directory, verbose, ignoreExamples, ignoreTerms);
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}

					if (repositories.getDefaultRepository() != null && !ignoreGit) {
						Repository repository = repositories.getDefaultRepository();
						resetCheckout(repository);
					}
					for (Repository repository : repositories.getNamedRepositories()) {
						resetCheckout(repository);
					}

					testSuites.clean();

					reportAndExit((int) -Math.signum(testSuites.getErrors() + testSuites.getFailures()));

					int n = JOptionPane.showConfirmDialog(frame,
							"The pipeline is finished\n" + "The report file is available at:\n" + directory
									+ "/target/report_output.xml\n"
									+ "Would you like to open it, erase the console and start the pipeline again?",
							"Report results", JOptionPane.YES_NO_OPTION);
					if (n == 0) {
						try {
							txtConsole.setText("");
							Desktop.getDesktop().open(new File(directory + "/target/report_output.xml"));

						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}

				}

			}
		});
		functionalitiesPanel.add(startBtn);

		FlowLayout flowLayout_1 = (FlowLayout) infoPanel.getLayout();
		flowLayout_1.setVgap(20);
		flowLayout_1.setHgap(20);
		frame.getContentPane().add(infoPanel, BorderLayout.NORTH);

		frame.getContentPane().add(textAreaPanel, BorderLayout.CENTER);
		txtConsole.setColumns(70);
		txtConsole.setRows(15);
		textAreaPanel.add(txtConsole);

		JScrollPane scroll = new JScrollPane(txtConsole, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		frame.add(scroll);

		frame.pack();
		frame.setResizable(true);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		return true;
	}

	private static void setGUIAppenders() throws IOException {

		JTextAreaAppender jTextAreaAppender = new JTextAreaAppender(txtConsole);

		org.apache.log4j.Logger appenderRootLogger = org.apache.log4j.Logger.getRootLogger();

		Layout GUIlayout = new PatternLayout("%d{mm:ss,SSS} %t %-5p %c:%L - %m%n");

		jTextAreaAppender.setLayout(GUIlayout);

		appenderRootLogger.addAppender(jTextAreaAppender);
	}

// ************************************************
	private static void prepareDirectory() throws IOException {
		target = new File(directory, Constants.TARGET_DIR);
		FileUtils.forceMkdir(target);
@@ -201,7 +471,6 @@ public class Main {
		}
	}


	private static Dataset createFreshDataset() throws IOException {
		File datasetDir = new File(directory, Constants.DATASET_DIR);
		FileUtils.forceMkdir(datasetDir);
@@ -210,7 +479,9 @@ public class Main {
		dataset.getDefaultModel().removeAll();
		List<String> toRemove = new ArrayList<>();
		Iterator<String> it = dataset.listNames();
		while(it.hasNext()) { toRemove.add(it.next()); }
		while (it.hasNext()) {
			toRemove.add(it.next());
		}
		for (String name : toRemove) {
			dataset.removeNamedModel(name);
		}
@@ -318,7 +589,6 @@ public class Main {
		return sm;
	}


	private static void resetCheckout(Repository repository) {
		try (Git git = Git.open(repository.getDirectory())) {
			String currentBranch = repository.getCurrentBranch();
@@ -345,14 +615,15 @@ public class Main {
				// generate the report.html
				File reportHTML = new File(directory, Constants.SITE_DIR + File.separator + "report.html");
				try (IndentedWriter writer = new IndentedWriter(new FileOutputStream(reportHTML));) {
					Context context = ContextUtils.build(writer).setBase(Constants.BASE)
							.setDebugTemplate(verbose).setStreamManager(streamManager).build();
					Context context = ContextUtils.build(writer).setBase(Constants.BASE).setDebugTemplate(verbose)
							.setStreamManager(streamManager).build();
					BindingHashMap binding = new BindingHashMap();
					binding.add(VAR_TEST_SUITES, NodeFactory.createLiteral(sw.toString()));
					List<Binding> bindings = new ArrayList<>();
					bindings.add(binding);
					String query = IOUtils.toString(
							streamManager.open(new LookUpRequest("documentation/report/main.rqg", SPARQLExt.MEDIA_TYPE)),
							streamManager
									.open(new LookUpRequest("documentation/report/main.rqg", SPARQLExt.MEDIA_TYPE)),
							StandardCharsets.UTF_8);
					RootPlan reportPlan = PlanFactory.create(query, BASE_DOC);
					reportPlan.execTemplateStream(bindings, context);
@@ -371,7 +642,8 @@ public class Main {
			ex.printStackTrace();
		}

		if (!isTheConsoleActive) {
			System.exit(code);
		}

	}
}
+2.38 KiB
Loading image diff...
Loading