This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor AbstractToolOperation and related.
- Loading branch information
1 parent
f6e4625
commit d874798
Showing
9 changed files
with
155 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
plugin_tooling/src-lang/melnorme/lang/tooling/data/InfoResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/******************************************************************************* | ||
* 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.tooling.data; | ||
|
||
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull; | ||
|
||
@SuppressWarnings("serial") | ||
public class InfoResult extends Throwable { | ||
|
||
public InfoResult(String message) { | ||
super(assertNotNull(message)); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return super.getMessage(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
plugin_tooling/src-lang/melnorme/lang/tooling/ops/AbstractToolOutputParser2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 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.tooling.ops; | ||
|
||
|
||
import melnorme.lang.tooling.data.InfoResult; | ||
import melnorme.utilbox.concurrency.ICancelMonitor; | ||
import melnorme.utilbox.concurrency.OperationCancellation; | ||
import melnorme.utilbox.core.CommonException; | ||
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult; | ||
|
||
public abstract class AbstractToolOutputParser2<RESULT> extends ToolOutputParseHelper { | ||
|
||
protected final String toolPath; | ||
protected final boolean nonZeroExitIsFatal; | ||
|
||
public AbstractToolOutputParser2(String toolPath, boolean nonZeroResultIsFatal) { | ||
super(); | ||
this.toolPath = toolPath; | ||
this.nonZeroExitIsFatal = nonZeroResultIsFatal; | ||
} | ||
|
||
public FindDefinitionResult execute(IProcessRunner opRunner, | ||
ICancelMonitor cm) throws OperationCancellation, CommonException, InfoResult { | ||
ProcessBuilder pb = createProcessBuilder(); | ||
|
||
ExternalProcessResult result = opRunner.runProcess(pb, null, cm); | ||
if(result.exitValue != 0) { | ||
handleNonZeroExitValue(result); | ||
} | ||
|
||
return parseToolResult(result); | ||
} | ||
|
||
protected abstract ProcessBuilder createProcessBuilder() throws CommonException; | ||
|
||
@SuppressWarnings("unused") | ||
protected void handleNonZeroExitValue( ExternalProcessResult result) throws CommonException, InfoResult { | ||
String nonZeroExitMsg = getToolName() + " did not complete successfully."; | ||
if(nonZeroExitIsFatal) { | ||
throw new CommonException(nonZeroExitMsg); | ||
} else { | ||
throw new InfoResult(nonZeroExitMsg); | ||
} | ||
} | ||
|
||
protected abstract String getToolName(); | ||
|
||
public FindDefinitionResult parseToolResult(ExternalProcessResult result) throws CommonException { | ||
return parseToolResult(result.getStdOutBytes().toString()); | ||
} | ||
|
||
public abstract FindDefinitionResult parseToolResult(String output) throws CommonException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
plugin_tooling/src-lang/melnorme/lang/tooling/ops/IProcessRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* 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.tooling.ops; | ||
|
||
import melnorme.utilbox.concurrency.ICancelMonitor; | ||
import melnorme.utilbox.concurrency.OperationCancellation; | ||
import melnorme.utilbox.core.CommonException; | ||
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult; | ||
|
||
public interface IProcessRunner { | ||
|
||
/** | ||
* Start a process from given ProcessBuilder pb, run it with given input until completion. | ||
*/ | ||
ExternalProcessResult runProcess(ProcessBuilder pb, String input, ICancelMonitor cm) | ||
throws OperationCancellation, CommonException; | ||
|
||
} |