Commit 620b48d0 authored by Omar ALQAWASMEH's avatar Omar ALQAWASMEH
Browse files

Joption pane is added to fetch username/password

parent 2451fa3b
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -5,6 +5,8 @@ import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
import java.nio.file.PathMatcher;
import java.util.regex.Pattern;
import java.util.regex.Pattern;


import javax.swing.JFrame;

public class Constants {
public class Constants {
	public final static String BASE = "https://saref.etsi.org/";
	public final static String BASE = "https://saref.etsi.org/";


@@ -26,4 +28,8 @@ public class Constants {


	public static final String CONFIG = BASE + "config";
	public static final String CONFIG = BASE + "config";
	
	
	public static boolean isTheConsoleActive = true;
	public static JFrame frame = new JFrame();

	
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -110,6 +110,8 @@ public class JTextAreaAppender extends AppenderSkeleton {
		}
		}
		
		
		jTextArea.update(jTextArea.getGraphics());
		jTextArea.update(jTextArea.getGraphics());
//	    DefaultCaret caret = (DefaultCaret)jTextArea.getCaret();
//	    caret.setUpdatePolicy(DefaultCaret.OUT_BOTTOM);


		// scroll TextArea
		// scroll TextArea
//		jTextArea.setCaretPosition(jTextArea.getText().length());
//		jTextArea.setCaretPosition(jTextArea.getText().length());
+18 −18
Original line number Original line Diff line number Diff line
@@ -127,11 +127,10 @@ public class Main {


	private static JTextArea txtConsole = new JTextArea("Select a directory to start\n");
	private static JTextArea txtConsole = new JTextArea("Select a directory to start\n");
	private static JScrollPane scroll = new JScrollPane();
	private static JScrollPane scroll = new JScrollPane();
	private static JFrame frame = new JFrame();
	private static JPanel functionalitiesPanel = new JPanel(new GridLayout(0, 4));
	private static JPanel functionalitiesPanel = new JPanel(new GridLayout(0, 4));
	private static JPanel infoPanel = new JPanel();
	private static JPanel infoPanel = new JPanel();
	private static JPanel textAreaPanel = new JPanel();
	private static JPanel textAreaPanel = new JPanel();
	public static boolean isTheConsoleActive = true;
	
	private static String lastPath;
	private static String lastPath;
	private static JFileChooser fileChooser;
	private static JFileChooser fileChooser;
	
	
@@ -140,7 +139,7 @@ public class Main {
	public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException, JAXBException,
	public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException, JAXBException,
			ParseException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException,
			ParseException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException,
			CheckoutConflictException, GitAPIException {
			CheckoutConflictException, GitAPIException {
		if (isTheConsoleActive == true) {
		if (Constants.isTheConsoleActive == true) {


			openConsole(); // open console
			openConsole(); // open console


@@ -249,16 +248,16 @@ public class Main {


//		JFrame.setDefaultLookAndFeelDecorated(true);
//		JFrame.setDefaultLookAndFeelDecorated(true);


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


		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Constants.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


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


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


		JLabel lbl = new JLabel("The list of arguments:");
		JLabel lbl = new JLabel("The list of arguments:");
		functionalitiesPanel.add(lbl);
		functionalitiesPanel.add(lbl);
@@ -327,7 +326,7 @@ public class Main {
				}
				}
				
				
				fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				int option = fileChooser.showOpenDialog(frame);
				int option = fileChooser.showOpenDialog(Constants.frame);
				if (option == JFileChooser.APPROVE_OPTION) {
				if (option == JFileChooser.APPROVE_OPTION) {
					directory = fileChooser.getSelectedFile();
					directory = fileChooser.getSelectedFile();
					fileSelected = true;
					fileSelected = true;
@@ -410,6 +409,7 @@ public class Main {


					Repositories repositories;
					Repositories repositories;
					try {
					try {
						LOG.info("eeeee");
						repositories = new ReadRepositories("Fetching required repositories")
						repositories = new ReadRepositories("Fetching required repositories")
								.readRepositories(directory, remoteOnly, ignoreGit, includeMaster);
								.readRepositories(directory, remoteOnly, ignoreGit, includeMaster);
					} catch (Exception ex) {
					} catch (Exception ex) {
@@ -452,7 +452,7 @@ public class Main {


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


					int n = JOptionPane.showConfirmDialog(frame,
					int n = JOptionPane.showConfirmDialog(Constants.frame,
							"The pipeline is finished\n" + "The report file is available at:\n" + directory
							"The pipeline is finished\n" + "The report file is available at:\n" + directory
									+ "/target/report_output.xml\n"
									+ "/target/report_output.xml\n"
									+ "Would you like to open it, erase the console and start the pipeline again?",
									+ "Would you like to open it, erase the console and start the pipeline again?",
@@ -477,9 +477,9 @@ public class Main {
		FlowLayout flowLayout_1 = (FlowLayout) infoPanel.getLayout();
		FlowLayout flowLayout_1 = (FlowLayout) infoPanel.getLayout();
		flowLayout_1.setVgap(20);
		flowLayout_1.setVgap(20);
		flowLayout_1.setHgap(20);
		flowLayout_1.setHgap(20);
		frame.getContentPane().add(infoPanel, BorderLayout.NORTH);
		Constants.frame.getContentPane().add(infoPanel, BorderLayout.NORTH);


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


@@ -487,12 +487,12 @@ public class Main {


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


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


		return true;
		return true;
	}
	}
@@ -680,7 +680,7 @@ public class Main {
			LOG.error("Exception:", ex);
			LOG.error("Exception:", ex);
			ex.printStackTrace();
			ex.printStackTrace();
		}
		}
		if (!isTheConsoleActive) {
		if (!Constants.isTheConsoleActive) {
			
			
			System.exit(code);
			System.exit(code);
		}
		}
+12 −0
Original line number Original line Diff line number Diff line
@@ -11,6 +11,8 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.Pattern;


import javax.swing.JOptionPane;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.text.StringSubstitutor;
import org.apache.commons.text.StringSubstitutor;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Git;
@@ -155,6 +157,11 @@ public class ReadRepositories extends JobRunner {
			} else if (System.getenv("GITLAB_CI") != null) {
			} else if (System.getenv("GITLAB_CI") != null) {
				LOG.info("using username 'gitlab-ci-token'");
				LOG.info("using username 'gitlab-ci-token'");
				username = "gitlab-ci-token";
				username = "gitlab-ci-token";
			}else if (Constants.isTheConsoleActive == true) {
				LOG.info("Please enter your account username for %s:\t" + hostName);
				username = JOptionPane.showInputDialog(Constants.frame,
						"Please enter your account username for \n" + hostName, null);

			} else {
			} else {
				LOG.warn("using empty username");
				LOG.warn("using empty username");
				username = "";
				username = "";
@@ -168,6 +175,11 @@ public class ReadRepositories extends JobRunner {
						.readPassword(String.format("Please enter your account password for %s:\n", hostName));
						.readPassword(String.format("Please enter your account password for %s:\n", hostName));
			} else if (System.getenv("GITLAB_CI") != null) {
			} else if (System.getenv("GITLAB_CI") != null) {
				password = System.getenv("CI_JOB_TOKEN").toCharArray();
				password = System.getenv("CI_JOB_TOKEN").toCharArray();
			}  else if (Constants.isTheConsoleActive == true) {
				password = JOptionPane
						.showInputDialog(Constants.frame, "Please enter your account password for \n" + hostName, null)
						.toCharArray();

			} else {
			} else {
				LOG.warn("using empty password");
				LOG.warn("using empty password");
				password = "".toCharArray();
				password = "".toCharArray();