Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
Minor utils addendum
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Apr 14, 2016
1 parent 11b4c7a commit f82a5f9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
Expand Up @@ -18,7 +18,6 @@
import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.junit.Test;

Expand All @@ -35,6 +34,7 @@
import melnorme.lang.ide.core.operations.build.BuildManager_Test.TestsBuildManager.SampleStrictBuildType;
import melnorme.lang.ide.core.project_model.LangBundleModel;
import melnorme.lang.ide.core.tests.BuildTestsHelper;
import melnorme.lang.ide.core.tests.CoreTestWithProject;
import melnorme.lang.ide.core.tests.SampleProject;
import melnorme.lang.tooling.bundle.BuildConfiguration;
import melnorme.lang.tooling.bundle.BuildTargetNameParser;
Expand All @@ -44,9 +44,8 @@
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;
import melnorme.utilbox.tests.CommonTest;

public class BuildManager_Test extends CommonTest {
public class BuildManager_Test extends CoreTestWithProject {

public static final BuildTargetData sampleBT_A =
bt("TargetA", true, false, null, null);
Expand Down Expand Up @@ -152,15 +151,6 @@ protected BuildConfiguration getValidBuildconfiguration(String buildConfigName,

protected String SEP = buildMgr.getBuildTargetNameParser().getNameSeparator();

protected SampleProject sampleProject;
protected IProject project;

protected SampleProject initSampleProject() throws CoreException, CommonException {
this.sampleProject = new SampleProject(getClass().getSimpleName());
this.project = sampleProject.getProject();
return sampleProject;
}

protected final BundleInfo bundleInfo = BuildTestsHelper.createSampleBundleInfoA("SampleBundle", null);

/* ----------------- ----------------- */
Expand Down Expand Up @@ -286,7 +276,7 @@ public void checkBuildTargets(Indexable<BuildTarget> buildTargets, Indexable<Bui

protected CompositeBuildTargetSettings btSettings(
String buildTargetName, String buildArguments, String artifactPath) {
return getBuiltTargetSettingsValidator(sampleProject.getName(), buildTargetName, buildArguments, artifactPath);
return getBuiltTargetSettingsValidator(project.getName(), buildTargetName, buildArguments, artifactPath);
}

protected CompositeBuildTargetSettings getBuiltTargetSettingsValidator(
Expand Down
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2016 Bruno Medeiros and other Contributors.
* 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:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.tests;


import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;

import melnorme.lang.ide.core.tests.CommonCoreTest_ActualClass;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.ownership.IDisposable;

public abstract class CoreTestWithProject extends CommonCoreTest_ActualClass {

public CoreTestWithProject() {
super();
}

protected SampleProject sampleProject;
protected IProject project;

protected SampleProject initSampleProject() throws CoreException, CommonException {
this.sampleProject = new SampleProject(getClass().getSimpleName());
return setSampleProject(sampleProject);
}

protected SampleProject setSampleProject(SampleProject sampleProject) {
this.project = sampleProject.getProject();

owned.add(new IDisposable() {
@Override
public void dispose() {
try {
sampleProject.cleanUp();
} catch(CoreException e) {
throw melnorme.utilbox.core.ExceptionAdapter.unchecked(e);
}
}
});
return sampleProject;
}

}
Expand Up @@ -94,7 +94,7 @@ protected ArrayList2<String> evaluateBuildCommand(String toolCommandLine) throws
return new ArrayList2<>(evaluatedArguments);
}

protected ProcessBuilder getToolProcessBuilder() throws CommonException, OperationCancellation {
public ProcessBuilder getToolProcessBuilder() throws CommonException, OperationCancellation {
return getProcessBuilder3(getEffectiveProccessCommandLine());
}

Expand Down
Expand Up @@ -306,6 +306,10 @@ public static void deleteProject_unchecked(String projectName) {

public static void tryDeleteProject(String projectName) throws CoreException {
IProject project = EclipseUtils.getWorkspaceRoot().getProject(projectName);
tryDeleteProject(project);
}

public static void tryDeleteProject(IProject project) throws CoreException {
try {
project.delete(true, null);
} catch (CoreException ce) {
Expand Down
5 changes: 5 additions & 0 deletions plugin_tooling/src-util/melnorme/utilbox/misc/Location.java
Expand Up @@ -71,6 +71,11 @@ public static Location createValidOrNull(Path path) {
}
}

/** @return a new {@link Location} from given path, or null if pathString is not valid. */
public static Location createValidOrNull(String pathString) {
return Location.createValidOrNull(PathUtil.createPathOrNull(pathString));
}

/**
* @return Create a location based on given baseLocation if given pathString is a relative path,
* otherwise return the pathString location.
Expand Down

0 comments on commit f82a5f9

Please sign in to comment.