summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkwilk2012-04-17 18:58:48 (EDT)
committer Roberto E. Escobar2012-04-17 18:58:48 (EDT)
commit2d7d09a0bd4911652522d3955fab453b0118dbe4 (patch)
tree9644ef89259027ee2ed5a9530511cd8b33b7fae1
parentc545d7f5f0ed6bf416b478c8cb023fbdbff2cfa5 (diff)
downloadorg.eclipse.osee-2d7d09a0bd4911652522d3955fab453b0118dbe4.zip
org.eclipse.osee-2d7d09a0bd4911652522d3955fab453b0118dbe4.tar.gz
org.eclipse.osee-2d7d09a0bd4911652522d3955fab453b0118dbe4.tar.bz2
refactor: Code quality refactor
-rw-r--r--plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranch.java63
-rw-r--r--plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranchEnablement.java101
-rw-r--r--plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DatabaseInitializationOperation.java16
-rw-r--r--plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ServerLookupServlet.java4
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/AttributePurgeTest.java2
-rw-r--r--plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java29
6 files changed, 77 insertions, 138 deletions
diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranch.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranch.java
index ee92eb7..6757d8c 100644
--- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranch.java
+++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranch.java
@@ -91,21 +91,13 @@ public class XWorkingBranch extends GenericXWidget implements IArtifactWidget, I
Changes_NotPermitted__CreationInProgress("Branch Being Created - No Changes Permitted", false),
Changes_NotPermitted__CommitInProgress("Branch Being Committed - No Changes Permitted", false);
- private final String displayName;
- private final boolean changesPermitted;
+ public final String displayName;
+ public final boolean changesPermitted;
private BranchStatus(String displayName, boolean changesPermitted) {
this.displayName = displayName;
this.changesPermitted = changesPermitted;
}
-
- public String getDisplayName() {
- return displayName;
- }
-
- public boolean isChangesPermitted() {
- return changesPermitted;
- }
}
public XWorkingBranch() {
@@ -336,14 +328,10 @@ public class XWorkingBranch extends GenericXWidget implements IArtifactWidget, I
public void refreshLabel() {
if (labelWidget != null && Widgets.isAccessible(labelWidget) && !getLabel().equals("")) {
- try {
- Branch workBranch = enablement.getWorkingBranch();
- String labelStr =
- getLabel() + ": " + enablement.getStatus().getDisplayName() + (workBranch != null ? " - " + workBranch.getShortName() : "");
- labelWidget.setText(labelStr);
- } catch (OseeCoreException ex) {
- OseeLog.log(Activator.class, Level.SEVERE, ex);
- }
+ Branch workBranch = enablement.getWorkingBranch();
+ String labelStr =
+ getLabel() + ": " + enablement.getStatus().displayName + (workBranch != null ? " - " + workBranch.getShortName() : "");
+ labelWidget.setText(labelStr);
if (getToolTip() != null) {
labelWidget.setToolTipText(getToolTip());
}
@@ -384,32 +372,25 @@ public class XWorkingBranch extends GenericXWidget implements IArtifactWidget, I
}
public void refreshOnBranchEvent() {
- if (teamArt == null || labelWidget == null || labelWidget.isDisposed()) {
- return;
- }
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- try {
+ if (teamArt != null || labelWidget != null || !labelWidget.isDisposed()) {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
enablement.refresh();
enablement.getStatus();
- } catch (OseeCoreException ex) {
- OseeLog.log(Activator.class, Level.SEVERE, ex);
- }
- Displays.ensureInDisplayThread(new Runnable() {
- @Override
- public void run() {
- if (Widgets.isAccessible(createBranchButton)) {
- refreshEnablement();
- refreshLabel();
- refreshLockImage();
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ if (Widgets.isAccessible(createBranchButton)) {
+ refreshEnablement();
+ refreshLabel();
+ refreshLockImage();
+ }
}
- }
- });
- }
- };
- Thread thread = new Thread(runnable);
- thread.start();
+ });
+ }
+ }).start();
+ }
}
@Override
diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranchEnablement.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranchEnablement.java
index e0dc80d..0328b5e 100644
--- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranchEnablement.java
+++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/XWorkingBranchEnablement.java
@@ -35,69 +35,23 @@ public class XWorkingBranchEnablement {
}
public boolean isCreateBranchButtonEnabled() {
- if (disableAll) {
- return false;
- }
- try {
- ensurePopulated();
- return !workingBranchCommitInProgress && !workingBranchCreationInProgress && !workingBranchInWork && !committedBranchExists;
- } catch (OseeCoreException ex) {
- OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
- }
- return false;
-
+ return !disableAll && ensurePopulatedLogError() && !workingBranchCommitInProgress && !workingBranchCreationInProgress && !workingBranchInWork && !committedBranchExists;
}
public boolean isShowArtifactExplorerButtonEnabled() {
- if (disableAll) {
- return false;
- }
- try {
- ensurePopulated();
- return workingBranch != null && getStatus().isChangesPermitted();
- } catch (OseeCoreException ex) {
- OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
- }
- return false;
+ return !disableAll && ensurePopulatedLogError() && workingBranch != null && getStatus().changesPermitted;
}
public boolean isShowChangeReportButtonEnabled() {
- if (disableAll) {
- return false;
- }
- try {
- ensurePopulated();
- return workingBranchInWork || committedBranchExists;
- } catch (OseeCoreException ex) {
- OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
- }
- return false;
+ return !disableAll && ensurePopulatedLogError() && (workingBranchInWork || committedBranchExists);
}
public boolean isDeleteBranchButtonEnabled() {
- if (disableAll) {
- return false;
- }
- try {
- ensurePopulated();
- return workingBranchInWork && !committedBranchExists;
- } catch (OseeCoreException ex) {
- OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
- }
- return false;
+ return !disableAll && ensurePopulatedLogError() && workingBranchInWork && !committedBranchExists;
}
public boolean isFavoriteBranchButtonEnabled() {
- if (disableAll) {
- return false;
- }
- try {
- ensurePopulated();
- return workingBranchInWork;
- } catch (OseeCoreException ex) {
- OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
- }
- return false;
+ return !disableAll && ensurePopulatedLogError() && workingBranchInWork;
}
public synchronized void refresh() {
@@ -105,8 +59,8 @@ public class XWorkingBranchEnablement {
disableAll = false;
}
- public BranchStatus getStatus() throws OseeCoreException {
- ensurePopulated();
+ public BranchStatus getStatus() {
+ ensurePopulatedLogError();
if (teamArt != null) {
if (workingBranchCreationInProgress) {
return BranchStatus.Changes_NotPermitted__CreationInProgress;
@@ -121,21 +75,6 @@ public class XWorkingBranchEnablement {
return BranchStatus.Not_Started;
}
- private synchronized void ensurePopulated() throws OseeCoreException {
- if (populated) {
- return;
- }
- workingBranch = AtsBranchManagerCore.getWorkingBranch(teamArt, true);
- workingBranchCreationInProgress =
- teamArt.isWorkingBranchCreationInProgress() || (workingBranch != null && workingBranch.getBranchState() == BranchState.CREATION_IN_PROGRESS);
- workingBranchCommitInProgress =
- teamArt.isWorkingBranchCommitInProgress() || workingBranch != null && workingBranch.getBranchState() == BranchState.COMMIT_IN_PROGRESS;
- workingBranchInWork = AtsBranchManagerCore.isWorkingBranchInWork(teamArt);
- committedBranchExists = AtsBranchManagerCore.isCommittedBranchExists(teamArt);
- disableAll = workingBranchCommitInProgress;
- populated = true;
- }
-
public Branch getWorkingBranch() {
return workingBranch;
}
@@ -151,4 +90,30 @@ public class XWorkingBranchEnablement {
disableAll, workingBranchCreationInProgress, workingBranchCommitInProgress, workingBranchInWork,
committedBranchExists, workingBranch);
}
+
+ private synchronized void ensurePopulated() throws OseeCoreException {
+ if (!populated) {
+ workingBranch = AtsBranchManagerCore.getWorkingBranch(teamArt, true);
+ workingBranchCreationInProgress =
+ teamArt.isWorkingBranchCreationInProgress() || (workingBranch != null && workingBranch.getBranchState() == BranchState.CREATION_IN_PROGRESS);
+ workingBranchCommitInProgress =
+ teamArt.isWorkingBranchCommitInProgress() || workingBranch != null && workingBranch.getBranchState() == BranchState.COMMIT_IN_PROGRESS;
+ workingBranchInWork = AtsBranchManagerCore.isWorkingBranchInWork(teamArt);
+ committedBranchExists = AtsBranchManagerCore.isCommittedBranchExists(teamArt);
+ disableAll = workingBranchCommitInProgress;
+ populated = true;
+ }
+ }
+
+ private boolean ensurePopulatedLogError() {
+ boolean attemptedToPopulate = false;
+ try {
+ ensurePopulated();
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
+ } finally {
+ attemptedToPopulate = true;
+ }
+ return attemptedToPopulate;
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DatabaseInitializationOperation.java b/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DatabaseInitializationOperation.java
index 2c8450c..43f099a 100644
--- a/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DatabaseInitializationOperation.java
+++ b/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DatabaseInitializationOperation.java
@@ -258,20 +258,18 @@ public class DatabaseInitializationOperation {
}
public static void executeWithoutPrompting(String choice) throws OseeCoreException {
- new DatabaseInitializationOperation(choice, false).execute();
- }
-
- public static void executeWithPromptsAndChoice(String choice) throws OseeCoreException {
- new DatabaseInitializationOperation(choice, false).execute();
+ executeWithParams(choice, false);
}
public static void executeWithPrompts() throws OseeCoreException {
- new DatabaseInitializationOperation(null, true).execute();
+ executeWithParams(null, true);
}
public static void executeConfigureFromJvmProperties() throws OseeCoreException {
- boolean arePromptsAllowed = OseeClientProperties.promptOnDbInit();
- String predefinedChoice = OseeClientProperties.getChoiceOnDbInit();
- new DatabaseInitializationOperation(predefinedChoice, arePromptsAllowed).execute();
+ executeWithParams(OseeClientProperties.getChoiceOnDbInit(), OseeClientProperties.promptOnDbInit());
+ }
+
+ public static void executeWithParams(String choice, boolean promptsAllowed) throws OseeCoreException {
+ new DatabaseInitializationOperation(choice, promptsAllowed).execute();
}
}
diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ServerLookupServlet.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ServerLookupServlet.java
index 18a3964..6ad04cc 100644
--- a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ServerLookupServlet.java
+++ b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ServerLookupServlet.java
@@ -37,7 +37,6 @@ public class ServerLookupServlet extends UnsecuredOseeHttpServlet {
super(logger);
this.lookupService = lookupService;
this.applicationServerManager = applicationServerManager;
-
}
@Override
@@ -60,8 +59,6 @@ public class ServerLookupServlet extends UnsecuredOseeHttpServlet {
response.setCharacterEncoding("UTF-8");
response.getWriter().write(
String.format("Unable to locate application server matching version [%s]", version));
- response.getWriter().flush();
- response.getWriter().close();
} else {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
info.write(stream);
@@ -75,6 +72,7 @@ public class ServerLookupServlet extends UnsecuredOseeHttpServlet {
} catch (Exception ex) {
getLogger().error(ex, "Failed to process application server lookup request [%s]", request.toString());
response.getWriter().write(Lib.exceptionToString(ex));
+ } finally {
response.getWriter().flush();
response.getWriter().close();
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/AttributePurgeTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/AttributePurgeTest.java
index 7dcb297..b3cae85 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/AttributePurgeTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/AttributePurgeTest.java
@@ -39,7 +39,7 @@ public class AttributePurgeTest extends AbstractPurgeTest {
@Override
public void runPurgeOperation() throws OseeCoreException {
// Create some software artifacts
- Branch branch = BranchManager.getBranch(DemoSawBuilds.SAW_Bld_2.getName());
+ Branch branch = BranchManager.getBranch(DemoSawBuilds.SAW_Bld_2);
SkynetTransaction transaction = TransactionManager.createTransaction(branch, "Test purge artifacts");
Collection<Artifact> softArts =
FrameworkTestUtil.createSimpleArtifacts(CoreArtifactTypes.SoftwareRequirement, 10, getClass().getSimpleName(),
diff --git a/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java b/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java
index 954f96e..f78d224 100644
--- a/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java
+++ b/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/TestUtil.java
@@ -95,7 +95,7 @@ public class TestUtil {
for (IHealthStatus hStatus : monitorLog.getLogsAtLevel(level)) {
// do not count the valid ignored logs
for (String str : ignoreLogging) {
- if (hStatus.getMessage().startsWith(str) == false) {
+ if (!hStatus.getMessage().startsWith(str)) {
count++;
}
}
@@ -144,30 +144,27 @@ public class TestUtil {
public static void checkThatIncreased(Map<String, Integer> prevCount, Map<String, Integer> postCount) {
for (String name : prevCount.keySet()) {
+ Integer postC = postCount.get(name);
+ Integer prevC = prevCount.get(name);
if (!OseeProperties.isInTest()) {
- String incStr = postCount.get(name) > prevCount.get(name) ? "Increased" : "ERROR, Not Increased";
- System.out.println(String.format(incStr + ": [%s] pre[%d] vs post[%d]", name, prevCount.get(name),
- postCount.get(name)));
+ String incStr = postC > prevC ? "Increased" : "ERROR, Not Increased";
+ System.out.println(String.format(incStr + ": [%s] pre[%d] vs post[%d]", name, prevC, postC));
}
- }
- for (String name : prevCount.keySet()) {
- Assert.assertTrue(String.format("[%s] did not increase as expected: pre[%d] vs post[%d]", name,
- prevCount.get(name), postCount.get(name)), postCount.get(name) > prevCount.get(name));
+ Assert.assertTrue(String.format("[%s] did not increase as expected: pre[%d] vs post[%d]", name, prevC, postC),
+ postC > prevC);
}
}
public static void checkThatEqual(Map<String, Integer> prevCount, Map<String, Integer> postCount) {
for (String tableName : prevCount.keySet()) {
+ Integer postC = postCount.get(tableName);
+ Integer prevC = prevCount.get(tableName);
if (!OseeProperties.isInTest()) {
- String equalStr = postCount.get(tableName).equals(prevCount.get(tableName)) ? "Equal" : "ERROR, NotEqual";
- System.out.println(String.format(equalStr + ": [%s] pre[%d] post[%d]", tableName, prevCount.get(tableName),
- postCount.get(tableName)));
+ String equalStr = postC.equals(prevC) ? "Equal" : "ERROR, NotEqual";
+ System.out.println(String.format(equalStr + ": [%s] pre[%d] post[%d]", tableName, prevC, postC));
}
- }
- for (String tableName : prevCount.keySet()) {
- Assert.assertTrue(
- String.format("[%s] count not equal pre[%d] post[%d]", tableName, prevCount.get(tableName),
- postCount.get(tableName)), postCount.get(tableName).equals(prevCount.get(tableName)));
+ Assert.assertTrue(String.format("[%s] count not equal pre[%d] post[%d]", tableName, prevC, postC),
+ postC.equals(prevC));
}
}