Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorgan E. Cook2017-07-08 14:01:55 -0400
committerMorgan E. Cook2017-08-23 19:47:44 -0400
commit204a669ba0d50e5ff55cd32530653b1da9bf0d52 (patch)
tree107e2d010aae1e56af5fc3fa9dffed311735d1c0
parentbfcd4d0feef75f45bbd88c15b9cc844acc0db901 (diff)
downloadorg.eclipse.osee-204a669ba0d50e5ff55cd32530653b1da9bf0d52.tar.gz
org.eclipse.osee-204a669ba0d50e5ff55cd32530653b1da9bf0d52.tar.xz
org.eclipse.osee-204a669ba0d50e5ff55cd32530653b1da9bf0d52.zip
refactor: Move RenderUtil to framework.core
Signed-off-by: Morgan E. Cook <morgan.e.cook@boeing.com> Change-Id: I554a75bae1dfaa60395d2da91ce0999c2a5e22cc Signed-off-by: Morgan E. Cook <morgan.e.cook@boeing.com>
-rw-r--r--plugins/org.eclipse.osee.framework.core/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/OseeData.java72
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/RendererUtil.java146
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java5
4 files changed, 221 insertions, 3 deletions
diff --git a/plugins/org.eclipse.osee.framework.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.core/META-INF/MANIFEST.MF
index 205cb49cd28..d5ce0954db6 100644
--- a/plugins/org.eclipse.osee.framework.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.framework.core/META-INF/MANIFEST.MF
@@ -21,6 +21,7 @@ Import-Package: org.antlr.runtime,
org.codehaus.jackson.map.type,
org.codehaus.jackson.node,
org.eclipse.core.net.proxy,
+ org.eclipse.core.resources,
org.eclipse.osee.framework.jdk.core.text,
org.eclipse.osee.framework.jdk.core.text.change,
org.eclipse.osee.framework.jdk.core.text.rules,
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/OseeData.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/OseeData.java
index 5c2d88cbed5..60488a4d8f3 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/OseeData.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/OseeData.java
@@ -10,6 +10,19 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.data;
+import java.io.File;
+import java.util.logging.Level;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+
/**
* @author Donald G. Dunne
*/
@@ -22,9 +35,66 @@ public class OseeData {
public static final String BRANCH_ID_SEQ = "SKYNET_BRANCH_ID_SEQ";
public static final String TRANSACTION_ID_SEQ = "SKYNET_TRANSACTION_ID_SEQ";
+ private static final String OSEE_DATA_FOLDER_NAME = "osee.data";
+ private static IProject project;
private OseeData() {
- // utility class
+ // Utility class
+ }
+
+ public static synchronized void ensureProjectReady() {
+ if (project == null) {
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ project = workspaceRoot.getProject(OSEE_DATA_FOLDER_NAME);
+ }
+ if (!project.exists()) {
+ try {
+ project.create(null);
+ project.open(null);
+ } catch (CoreException ex) {
+ OseeLog.log(OseeData.class, Level.SEVERE, ex);
+ }
+ }
+ if (!project.isOpen()) {
+ OseeLog.logf(OseeData.class, Level.INFO, "[%s] project is closed; re-opening",
+ OSEE_DATA_FOLDER_NAME);
+ try {
+ project.open(null);
+ } catch (CoreException e) {
+ OseeLog.log(OseeData.class, Level.SEVERE, e);
+ }
+ }
}
+ public static IProject getProject() {
+ ensureProjectReady();
+ return project;
+ }
+
+ public static IPath getPath() {
+ IPath workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
+ return workspacePath.append(OSEE_DATA_FOLDER_NAME);
+ }
+
+ public static File getFile(String filename) {
+ ensureProjectReady();
+ return new File(getPath().toFile(), filename);
+ }
+
+ public static File getWorkspaceFile(String path) {
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ return new File(workspaceRoot.getFile(new Path(path)).getLocation().toString());
+ }
+
+ public static IFolder getFolder(String name) throws OseeCoreException {
+ try {
+ IFolder folder = getProject().getFolder(name);
+ if (!folder.exists()) {
+ folder.create(true, true, null);
+ }
+ return folder;
+ } catch (CoreException ex) {
+ throw OseeCoreException.wrap(ex);
+ }
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/RendererUtil.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/RendererUtil.java
new file mode 100644
index 00000000000..f88a77609a5
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/util/RendererUtil.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.util;
+
+import java.net.URLEncoder;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Random;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.data.OseeData;
+import org.eclipse.osee.framework.core.enums.PresentationType;
+import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+public class RendererUtil {
+
+ private static IFolder workingFolder;
+ private static IFolder compareFolder;
+ private static IFolder previewFolder;
+
+ private static final String FILENAME_WARNING_MESSAGE =
+ "\n\nis approaching a large size which may cause the opening application to error. " + "\nSuggest moving your workspace to avoid potential errors. ";
+
+ private static final Random generator = new Random();
+ private static final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
+ private static final int FILENAME_LIMIT = 215;
+
+ public static String toFileName(IOseeBranch branch) throws OseeCoreException {
+ // replace invalid filename characters \/:"*?<>| and . and ' with _
+ String shortName = Strings.saferReplace(branch.getShortName(), "[\\.\\/:\"*?<>|'\\\\]+", "_");
+ return encode(shortName);
+ }
+
+ private static String encode(String name) throws OseeCoreException {
+ String toReturn = null;
+ try {
+ toReturn = URLEncoder.encode(name, "UTF-8");
+ } catch (Exception ex) {
+ OseeCoreException.wrapAndThrow(ex);
+ }
+ return toReturn;
+ }
+
+ private static String constructFilename(String mainName, String fileNamePrefix, String extension) {
+ StringBuilder name = new StringBuilder(128);
+ if (Strings.isValid(fileNamePrefix)) {
+ name.append(fileNamePrefix);
+ name.append("_");
+ }
+
+ name.append(mainName);
+ name.append("_");
+ name.append(dateFormat.format(new Date()));
+ name.append("-");
+ name.append(generator.nextInt(99999) + 1);
+ name.append(extension);
+ return name.toString();
+ }
+
+ public static IFile getRenderFile(IOseeBranch branch, PresentationType presentationType, String pathPrefix, String mainName, String extension) {
+ String subFolder = toFileName(branch);
+ String fileNamePrefix = null;
+ if (Strings.isValid(pathPrefix)) {
+ int index = pathPrefix.lastIndexOf("/");
+ if (index != -1) {
+ subFolder = pathPrefix.substring(0, index);
+ }
+ fileNamePrefix = pathPrefix.substring(index + 1);
+ fileNamePrefix = fileNamePrefix.trim();
+ }
+ subFolder = subFolder.trim();
+ String fileName = constructFilename(mainName, fileNamePrefix, extension);
+ return getRenderFile(subFolder, fileName, presentationType);
+ }
+
+ private static IFile getRenderFile(String subFolder, String fileName, PresentationType presentationType) throws OseeCoreException {
+ try {
+ IFolder baseFolder = ensureRenderFolderExists(presentationType);
+ IFolder renderFolder = baseFolder.getFolder(subFolder);
+ if (!renderFolder.exists()) {
+ renderFolder.create(true, true, null);
+ }
+ IFile file = renderFolder.getFile(fileName);
+
+ return file;
+ } catch (CoreException ex) {
+ throw OseeCoreException.wrap(ex);
+ }
+ }
+
+ public static IFolder ensureRenderFolderExists(PresentationType presentationType) throws OseeCoreException {
+ IFolder toReturn = null;
+ switch (presentationType) {
+ case MERGE:
+ case DIFF:
+ compareFolder = getOrCreateFolder(compareFolder, ".compare");
+ toReturn = compareFolder;
+ break;
+ case SPECIALIZED_EDIT:
+ workingFolder = getOrCreateFolder(workingFolder, ".working");
+ toReturn = workingFolder;
+ break;
+ case PREVIEW:
+ previewFolder = getOrCreateFolder(previewFolder, ".preview");
+ toReturn = previewFolder;
+ break;
+ default:
+ throw new OseeArgumentException("Unexpected presentation type: %s", presentationType);
+ }
+ return toReturn;
+ }
+
+ private static IFolder getOrCreateFolder(IFolder folder, String name) throws OseeCoreException {
+ IFolder toCheck = folder;
+ if (toCheck == null || !toCheck.exists()) {
+ toCheck = OseeData.getFolder(name);
+ }
+ return toCheck;
+ }
+
+ public static boolean ensureFilenameLimit(IFile file) {
+ boolean withinLimit = true;
+ if (Lib.isWindows()) {
+ String absPath = file.getLocation().toFile().getAbsolutePath();
+ if (absPath.length() > FILENAME_LIMIT) {
+ withinLimit = false;
+ }
+ }
+ return withinLimit;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java
index 447a7e2c7bd..74991c66bcc 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/word/WordTemplateProcessor.java
@@ -57,6 +57,7 @@ import org.eclipse.osee.framework.core.model.datarights.DataRightResult;
import org.eclipse.osee.framework.core.model.type.AttributeType;
import org.eclipse.osee.framework.core.util.PageOrientation;
import org.eclipse.osee.framework.core.util.RendererOption;
+import org.eclipse.osee.framework.core.util.RendererUtil;
import org.eclipse.osee.framework.core.util.ReportConstants;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
@@ -237,8 +238,8 @@ public class WordTemplateProcessor {
getExcludeArtifactTypes();
- IFile file =
- RenderingUtil.getRenderFile(renderer, COMMON, PREVIEW, "/", masterTemplateArtifact.getSafeName(), ".xml");
+ IFile file = RendererUtil.getRenderFile(COMMON, PREVIEW, "/", masterTemplateArtifact.getSafeName(), ".xml");
+ renderer.updateOption(RendererOption.RESULT_PATH_RETURN, file.getLocation().toOSString());
AIFile.writeToFile(file, applyTemplate(artifacts, masterTemplate, masterTemplateOptions, masterTemplateStyles,
file.getParent(), null, null, PREVIEW));

Back to the top