diff options
Diffstat (limited to 'rba.tool.core/src/rba/tool/core/util')
12 files changed, 696 insertions, 0 deletions
diff --git a/rba.tool.core/src/rba/tool/core/util/EmptyToolLogger.java b/rba.tool.core/src/rba/tool/core/util/EmptyToolLogger.java new file mode 100644 index 0000000..cf2280d --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/EmptyToolLogger.java @@ -0,0 +1,20 @@ +package rba.tool.core.util;
+
+/**
+ * @author kousuke_morishima
+ */
+public class EmptyToolLogger implements IToolLogger {
+
+ public EmptyToolLogger() {
+ }
+
+ @Override
+ public void logging(Throwable e) {
+ // nothing to do
+ }
+
+ @Override
+ public void logging(String message) {
+ // nothing to do
+ }
+}
diff --git a/rba.tool.core/src/rba/tool/core/util/IToolLogger.java b/rba.tool.core/src/rba/tool/core/util/IToolLogger.java new file mode 100644 index 0000000..b53cf8c --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/IToolLogger.java @@ -0,0 +1,8 @@ +package rba.tool.core.util;
+
+public interface IToolLogger {
+
+ void logging(Throwable e);
+
+ void logging(String message);
+}
diff --git a/rba.tool.core/src/rba/tool/core/util/ModelUtil.java b/rba.tool.core/src/rba/tool/core/util/ModelUtil.java new file mode 100644 index 0000000..b6b34a7 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/ModelUtil.java @@ -0,0 +1,29 @@ +package rba.tool.core.util;
+
+import org.eclipse.emf.ecore.EObject;
+
+import rba.core.NamedElement;
+import rba.core.Package;
+
+public class ModelUtil {
+
+ public static final String SEPARATOR = "/";
+
+ public static String getRBAModelHierarchicalName(NamedElement target) {
+ return getRBAModelHierarchicalName(target, SEPARATOR);
+ }
+
+ public static String getRBAModelHierarchicalName(NamedElement target, String separator) {
+ EObject parent = target.eContainer();
+ if (parent == null || !(parent instanceof NamedElement) || parent instanceof Package) {
+ return target.getName();
+ } else {
+ return getRBAModelHierarchicalName((NamedElement) parent, separator) + separator + target.getName();
+ }
+ }
+
+ public static String convertModelName2ArbitrateName(String modelName) {
+ if (modelName == null) return modelName;
+ return modelName.replace(".", "/");
+ }
+}
diff --git a/rba.tool.core/src/rba/tool/core/util/ResourceUtil.java b/rba.tool.core/src/rba/tool/core/util/ResourceUtil.java new file mode 100644 index 0000000..751f308 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/ResourceUtil.java @@ -0,0 +1,72 @@ +package rba.tool.core.util; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +public class ResourceUtil { + public static BufferedReader getReader(File file) { + FileInputStream fis = null; + InputStreamReader isr = null; + BufferedReader reader = null; + + try { + fis = new FileInputStream(file); + isr = new InputStreamReader(fis, "UTF-8"); + reader = new BufferedReader(isr); + } catch (Throwable e) { + e.printStackTrace(); + try { + if (reader != null) { + reader.close(); + } + if (isr != null) { + isr.close(); + } + if (fis != null) { + fis.close(); + } + } catch (IOException e1) { + e1.printStackTrace(); + } + + throw new RuntimeException(e); + } + return reader; + } + + public static BufferedWriter getWriter(File file) { + FileOutputStream fos = null; + OutputStreamWriter osw = null; + BufferedWriter writer = null; + + try { + fos = new FileOutputStream(file); + osw = new OutputStreamWriter(fos, "UTF-8"); + writer = new BufferedWriter(osw); + } catch (Throwable e) { + e.printStackTrace(); + try { + if (writer != null) { + writer.close(); + } + if (osw != null) { + osw.close(); + } + if (fos != null) { + fos.close(); + } + } catch (IOException e1) { + e1.printStackTrace(); + } + + throw new RuntimeException(e); + } + return writer; + } +} diff --git a/rba.tool.core/src/rba/tool/core/util/SelectionTester.java b/rba.tool.core/src/rba/tool/core/util/SelectionTester.java new file mode 100644 index 0000000..b1bec63 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/SelectionTester.java @@ -0,0 +1,53 @@ +package rba.tool.core.util; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IResource; + +public class SelectionTester extends PropertyTester { + + @Override + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + if (property.equals("IsTestRev")) { + IFolder folder = SelectionUtil.getRevFolder(receiver); + return folder != null; + } + if (property.equals("IsResource")) { + return receiver instanceof IResource; + } + if (property.equals("IsMultiSelect")) { + IFolder folder = SelectionUtil.getRevFolder(receiver); + return folder != null; + } + if (property.equals("IsTestCompare")) { + IFolder folder = SelectionUtil.getRevCompareFolder(receiver); + return folder != null; + } + return false; + } + // + // protected boolean isEnableProject(Object receiver) { + // IResource resource = null; + // + // if (receiver instanceof EObject) { + // EObject eObject = (EObject) receiver; + // if (eObject.eResource() != null) { + // resource = WorkspaceSynchronizer.getFile(eObject.eResource()); + // } + // } else if (receiver instanceof IResource) { + // resource = (IResource) receiver; + // } + // + // if (resource != null) { + // IProject project = resource.getProject(); + // if (project != null) { + // // if (ZIPCProjectNature.hasNature(project)) { + // if (ZIPCProjectNature.hasNature(project) && DesignProjectNature.hasNature(project)) { + // return true; + // } + // } + // } + // return false; + // } + +} diff --git a/rba.tool.core/src/rba/tool/core/util/SelectionUtil.java b/rba.tool.core/src/rba/tool/core/util/SelectionUtil.java new file mode 100644 index 0000000..e6093b7 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/SelectionUtil.java @@ -0,0 +1,167 @@ +package rba.tool.core.util; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; + +public class SelectionUtil { + + public static final String TEST_FILE_NAME = "testinformation"; + + public static final String TEST_CASE_FOLDER_NAME = "testcase"; + + public static final String TEST_COVERAGE_FOLDER_NAME = "coverage"; + + public static final String TEST_LOG_FOLDER_NAME = "testlog"; + + public static final String TEST_RESULT_FOLDER_NAME = "testresult"; + + /** + * get testresult folder in revision folder from selected item + * @param file + * @return testcase folder + */ + public static IFolder getRevResultFolder(Object object) { + return getAndCreateFolderInTestRevFolder(object, TEST_RESULT_FOLDER_NAME); + } + + /** + * get testlog folder in revision folder from selected item + * @param file + * @return testcase folder + */ + public static IFolder getRevLogFolder(Object object) { + return getAndCreateFolderInTestRevFolder(object, TEST_LOG_FOLDER_NAME); + } + + /** + * get coverage folder in revision folder from selected item + * @param file + * @return testcase folder + */ + public static IFolder getRevCoverageFolder(Object object) { + return getAndCreateFolderInTestRevFolder(object, TEST_COVERAGE_FOLDER_NAME); + } + + /** + * get testcase folder in revision folder from selected item + * @param file + * @return testcase folder + */ + public static IFolder getRevTestcaseFolder(Object object) { + return getAndCreateFolderInTestRevFolder(object, TEST_CASE_FOLDER_NAME); + } + + public static IFolder getAndCreateFolderInTestRevFolder(Object object, String foldername) { + IFolder folder = getRevFolder(object); + if (folder != null) { + IFolder testcase = folder.getFolder(foldername); + if (!testcase.exists()) { + try { + testcase.create(true, true, null); + } catch (CoreException e) { + throw new RuntimeException(e); + } + } + return testcase; + } + return null; + } + + /** + * get revision folder of selected file + * @param file + * @return + */ + public static IFolder getRevFolder(Object object) { + try { + if (object instanceof ISelection) { + ISelection selection = (ISelection) object; + if (selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + Object element = structuredSelection.getFirstElement(); + if (element instanceof IResource) { + return getRevFolder((IResource) element); + } + } + } else if (object instanceof IResource) { + if (object instanceof IFolder) { + IFolder f = (IFolder) object; + IResource[] resources = f.members(); + for (IResource res : resources) { + if (res instanceof IFile) { + IFile file = (IFile) res; + if (file.getName().equals(TEST_FILE_NAME)) { + return f; + } + } + } + } else if (object instanceof IFile) { + IFolder parent = (IFolder) ((IFile) object).getParent(); + return getRevFolder(parent); + } + IResource r = (IResource) object; + return getRevFolder(r.getParent()); + + // + // IFolder f = null; + // if (object instanceof IFile) { + // IContainer parent = ((IFile) object).getParent(); + // if (parent instanceof IFolder) { + // f = (IFolder) parent; + // } + // } else + // + // if (f.getParent() instanceof IFolder) { + // return getRevFolder((IFolder) f.getParent()); + // } + } + } catch (CoreException e) { + e.printStackTrace(); + } + return null; + } + + /** + * to get only 2 selected revision file + * @param object + * @return + */ + public static IFolder getRevCompareFolder(Object object) { + try { + if (object instanceof ISelection) { + ISelection selection = (ISelection) object; + if (selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + if (structuredSelection.size() == 2) { + Object element = structuredSelection.getFirstElement(); + if (element instanceof IResource) { + return getRevCompareFolder((IResource) element); + } + } + } + } else if (object instanceof IResource) { + if (object instanceof IFolder) { + IFolder f = (IFolder) object; + IResource[] resources = f.members(); + for (IResource res : resources) { + if (res instanceof IFile) { + IFile file = (IFile) res; + if (file.getName().equals(TEST_FILE_NAME)) { + return f; + } + } + } + } + + } + } catch (CoreException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/rba.tool.core/src/rba/tool/core/util/SortResult.java b/rba.tool.core/src/rba/tool/core/util/SortResult.java new file mode 100644 index 0000000..838a325 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/SortResult.java @@ -0,0 +1,38 @@ +package rba.tool.core.util; + +import java.util.ArrayList; +import java.util.List; + +import rba.core.RuleObject; + +public class SortResult<T extends RuleObject> { + private List<SortResultSet<T>> sortResults = new ArrayList<SortResultSet<T>>(); + + private boolean isUnsat; + + public List<SortResultSet<T>> getSortResults() { + return sortResults; + } + + public boolean addSortResult(SortResultSet<T> sortResult) { + return sortResults.add(sortResult); + } + + public SortResultSet<T> getSortResultSet(RuleObject obj) { + for (SortResultSet<T> sortResult : sortResults) { + T element = sortResult.getElement(); + if (element.equals(obj)) { + return sortResult; + } + } + return null; + } + + public boolean isUnsat() { + return isUnsat; + } + + public void setUnsat(boolean isUnsat) { + this.isUnsat = isUnsat; + } +} diff --git a/rba.tool.core/src/rba/tool/core/util/SortResultSet.java b/rba.tool.core/src/rba/tool/core/util/SortResultSet.java new file mode 100644 index 0000000..93e18f0 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/SortResultSet.java @@ -0,0 +1,25 @@ +package rba.tool.core.util; + +import rba.core.RuleObject; + +public class SortResultSet<T extends RuleObject> { + private T element; + + private int value; + + public T getElement() { + return element; + } + + public void setElement(T element) { + this.element = element; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } +} diff --git a/rba.tool.core/src/rba/tool/core/util/ToolLogger.java b/rba.tool.core/src/rba/tool/core/util/ToolLogger.java new file mode 100644 index 0000000..0907eb6 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/ToolLogger.java @@ -0,0 +1,79 @@ +package rba.tool.core.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.FileHandler;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.SimpleFormatter;
+import java.util.stream.Stream;
+
+public class ToolLogger implements IToolLogger {
+
+ private Logger logger;
+
+ /**
+ * @param name logger name
+ * @param logFile File name
+ * @param append
+ * @throws SecurityException
+ * @throws IOException
+ */
+ public ToolLogger(String name, String logFile, boolean append) throws SecurityException, IOException {
+ this(Logger.getLogger(name), logFile, append);
+ }
+
+ /**
+ * @param logger logger name
+ * @param logFile
+ * @param append
+ * @throws SecurityException
+ * @throws IOException
+ * @throws NullPointerException
+ */
+ public ToolLogger(Logger logger, String logFile, boolean append) throws SecurityException, IOException {
+ if (logger == null) {
+ throw new NullPointerException("logger must be not null."); //$NON-NLS-1$
+ }
+ this.logger = logger;
+ String path = "log/" + logFile; //$NON-NLS-1$
+ createParent(path);
+ FileHandler h = new FileHandler(path, append);
+ h.setFormatter(new SimpleFormatter());
+ this.logger.addHandler(h);
+ this.logger.setLevel(Level.ALL);
+ }
+
+ public ToolLogger(Logger logger, Handler handler) {
+ if (logger == null) {
+ throw new NullPointerException("logger must be not null."); //$NON-NLS-1$
+ }
+ this.logger = logger;
+ this.logger.addHandler(handler);
+ this.logger.setLevel(Level.ALL);
+ }
+
+ static void createParent(String path) {
+ File logPath = new File(path);
+ if (!logPath.getParentFile().exists()) {
+ logPath.getParentFile().mkdirs();
+ }
+ }
+
+ /**
+ * Logging when handle to occurred error
+ * @param e
+ */
+ public void logging(Throwable e) {
+ StringBuilder message = new StringBuilder(e.toString() + "\n"); //$NON-NLS-1$
+ Stream.of(e.getStackTrace()).forEach(t -> message.append("\t").append(t.toString()).append("\n")); //$NON-NLS-1$ //$NON-NLS-2$
+ logger.warning(message.toString());
+ }
+
+ @Override
+ public void logging(String message) {
+ logger.warning(message);
+ }
+
+}
diff --git a/rba.tool.core/src/rba/tool/core/util/ValueSort.java b/rba.tool.core/src/rba/tool/core/util/ValueSort.java new file mode 100644 index 0000000..7182667 --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/ValueSort.java @@ -0,0 +1,152 @@ +package rba.tool.core.util; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import rba.core.ContentState; +import rba.core.Expression; +import rba.core.RBACoreFactory; +import rba.tool.core.sort.ValueGroup; +import rba.tool.core.sort.ValueSortedList; +import rba.view.Area; + +public class ValueSort { + public static ValueSort INSTANCE = new ValueSort(); + + public SortResult<Area> sortVisibility(List<Area> areas) { + SortResult<Area> sortResult = new SortResult<Area>(); + + try { + sortResult = doSortVisibility(areas); + sortResult.setUnsat(false); + } catch (RuntimeException e) { + sortResult.setUnsat(true); + } + + return sortResult; + } + + private SortResult<Area> doSortVisibility(List<Area> areas) { + SortResult<Area> sortResult = new SortResult<Area>(); + + Map<Area, SortResultSet<Area>> map = new HashMap<Area, SortResultSet<Area>>(); + for (Area area : areas) { + SortResultSet<Area> set = new SortResultSet<Area>(); + set.setElement(area); + sortResult.addSortResult(set); + map.put(area, set); + } + + ValueSortedList<Area> sortedElement = new ValueSortedList<Area>(areas) { + protected Expression getValueExpression(Area e) { + return e.getVisibility(); + } + }; + + for (ValueGroup<Area> valueGroup : sortedElement.getGroupList()) { + int value = convertValue(valueGroup.getName()); + for (Area member : valueGroup.getMember()) { + SortResultSet<Area> set = map.get(member); + set.setValue(value); + } + } + + return sortResult; + } + + public SortResult<Area> sortZorder(List<Area> areas) { + SortResult<Area> sortResult = new SortResult<Area>(); + + try { + sortResult = doSortZorder(areas); + sortResult.setUnsat(false); + } catch (RuntimeException e) { + sortResult.setUnsat(true); + } + + return sortResult; + } + + private SortResult<Area> doSortZorder(List<Area> areas) { + + SortResult<Area> sortResult = new SortResult<Area>(); + + Map<Area, SortResultSet<Area>> map = new HashMap<Area, SortResultSet<Area>>(); + for (Area area : areas) { + SortResultSet<Area> set = new SortResultSet<Area>(); + set.setElement(area); + sortResult.addSortResult(set); + map.put(area, set); + } + + ValueSortedList<Area> sortedElement = new ValueSortedList<Area>(areas) { + protected Expression getValueExpression(Area e) { + return e.getZorder(); + } + }; + + for (ValueGroup<Area> valueGroup : sortedElement.getGroupList()) { + int value = convertValue(valueGroup.getName()); + for (Area member : valueGroup.getMember()) { + SortResultSet<Area> set = map.get(member); + set.setValue(value); + } + } + return sortResult; + } + + public SortResult<ContentState> sortPriority(List<ContentState> contentStates) { + SortResult<ContentState> sortResult = new SortResult<ContentState>(); + + try { + sortResult = doSortPriority(contentStates); + sortResult.setUnsat(false); + } catch (RuntimeException e) { + sortResult.setUnsat(true); + } + + return sortResult; + } + + public SortResult<ContentState> doSortPriority(List<ContentState> contentStates) { + SortResult<ContentState> sortResult = new SortResult<ContentState>(); + + Map<ContentState, SortResultSet<ContentState>> map = new HashMap<ContentState, SortResultSet<ContentState>>(); + for (ContentState contentState : contentStates) { + SortResultSet<ContentState> set = new SortResultSet<ContentState>(); + set.setElement(contentState); + sortResult.addSortResult(set); + map.put(contentState, set); + } + + ValueSortedList<ContentState> sortedElement = new ValueSortedList<ContentState>(contentStates) { + protected Expression getValueExpression(ContentState e) { + return e.getValue(); + } + }; + + for (ValueGroup<ContentState> valueGroup : sortedElement.getGroupList()) { + int value = convertValue(valueGroup.getName()); + for (ContentState member : valueGroup.getMember()) { + SortResultSet<ContentState> set = map.get(member); + set.setValue(value); + } + } + + return sortResult; + } + + private int convertValue(String valueString) { + int value; + if (valueString.equals("MIN")) { + value = RBACoreFactory.eINSTANCE.createMinValue().getExpressionValue(); + } else if (valueString.equals("MAX")) { + value = RBACoreFactory.eINSTANCE.createMaxValue().getExpressionValue(); + } else { + value = Integer.parseInt(valueString); + } + return value; + } + +} diff --git a/rba.tool.core/src/rba/tool/core/util/data/ExCommentInfo.java b/rba.tool.core/src/rba/tool/core/util/data/ExCommentInfo.java new file mode 100644 index 0000000..936d8ae --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/data/ExCommentInfo.java @@ -0,0 +1,32 @@ +package rba.tool.core.util.data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExCommentInfo {
+
+ private String fileName;
+
+ private List<String> info = new ArrayList<String>();
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public List<String> getInfo() {
+ return info;
+ }
+
+ public void setInfo(List<String> info) {
+ this.info = info;
+ }
+
+ public void addInfo(String info) {
+ this.info.add(info);
+ }
+
+}
diff --git a/rba.tool.core/src/rba/tool/core/util/data/ExCommentLabel.java b/rba.tool.core/src/rba/tool/core/util/data/ExCommentLabel.java new file mode 100644 index 0000000..c83f03a --- /dev/null +++ b/rba.tool.core/src/rba/tool/core/util/data/ExCommentLabel.java @@ -0,0 +1,21 @@ +package rba.tool.core.util.data;
+
+public class ExCommentLabel {
+
+ private final String label;
+
+ private final int columnWidth;
+
+ public ExCommentLabel(String label, int columnWidth) {
+ this.label = label;
+ this.columnWidth = columnWidth;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public int getColumnWidth() {
+ return columnWidth;
+ }
+}
|