| author | Shawn F. Cook | 2011-08-02 16:05:32 (EDT) |
|---|---|---|
| committer | Ryan D. Brooks | 2011-08-02 16:05:32 (EDT) |
| commit | 694def2db13d9e45fe118fd4b8f508471582ca5e (patch) (side-by-side diff) | |
| tree | d8f71854f9bd446da01e86dfc3016a50a728847f | |
| parent | 79e69c9c937d627f25e69cd63c3c10fe23a6a890 (diff) | |
| download | org.eclipse.osee-694def2db13d9e45fe118fd4b8f508471582ca5e.zip org.eclipse.osee-694def2db13d9e45fe118fd4b8f508471582ca5e.tar.gz org.eclipse.osee-694def2db13d9e45fe118fd4b8f508471582ca5e.tar.bz2 | |
refinement[bgz_350331]: Migrate ParseWindowsDirectoryListing to server side command line
4 files changed, 86 insertions, 76 deletions
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/ParseWindowsDirectoryListingOperation.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/ParseWindowsDirectoryListingOperation.java new file mode 100644 index 0000000..38efe03 --- a/dev/null +++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/ParseWindowsDirectoryListingOperation.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2011 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.database.operation; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.operation.OperationLogger; +import org.eclipse.osee.framework.core.services.IOseeCachingService; +import org.eclipse.osee.framework.database.IOseeDatabaseService; +import org.eclipse.osee.framework.database.core.AbstractDbTxOperation; +import org.eclipse.osee.framework.database.core.OseeConnection; +import org.eclipse.osee.framework.database.internal.Activator; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Ryan D. Brooks + * @author Shawn F. Cook + */ +public class ParseWindowsDirectoryListingOperation extends AbstractDbTxOperation { + private static final String DIRECTORY_PREFIX = " Directory of Y:\\"; + private final String listingFile; + + public ParseWindowsDirectoryListingOperation(IOseeDatabaseService databaseService, IOseeCachingService cachingService, OperationLogger logger, String listingFile) { + super(databaseService, "Parsing Windows Directory Listing", Activator.PLUGIN_ID, logger); + this.listingFile = listingFile; + } + + @Override + protected void doTxWork(IProgressMonitor monitor, OseeConnection connection) throws OseeCoreException { + + log(); + log("Parsing windows directory listing:"); + + Matcher matcher = Pattern.compile("(\\d+/\\d+/\\d+).*<DIR>.*?SW\\\\(\\S+)\\s+(.*)").matcher(""); + BufferedWriter writer; + try { + writer = new BufferedWriter(new FileWriter(Lib.removeExtension(listingFile) + ".csv")); + + String path = null; + for (String line : Lib.readListFromFile(listingFile)) { + if (line.startsWith(DIRECTORY_PREFIX)) { + path = line.substring(DIRECTORY_PREFIX.length()); + } else { + matcher.reset(line); + if (matcher.find()) { + String summary = matcher.group(1) + "|" + matcher.group(2) + "|" + path + "\\" + matcher.group(3); + if (!summary.endsWith(".")) { + writer.write(summary); + writer.write(Lib.lineSeparator); + } + } + } + } + writer.close(); + } catch (IOException ex) { + log("ParseWindowsDirectoryListingOperation::doTxWork: Caught IOException:" + ex.toString()); + } finally { + log("...done."); + } + } +} diff --git a/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/ServerAdminCommandProvider.java b/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/ServerAdminCommandProvider.java index b340130..d41464e 100644 --- a/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/ServerAdminCommandProvider.java +++ b/plugins/org.eclipse.osee.framework.server.admin/src/org/eclipse/osee/framework/server/admin/ServerAdminCommandProvider.java @@ -27,6 +27,7 @@ import org.eclipse.osee.framework.core.operation.MutexSchedulingRule; import org.eclipse.osee.framework.core.operation.OperationLogger; import org.eclipse.osee.framework.core.operation.Operations; import org.eclipse.osee.framework.database.operation.ConsolidateArtifactVersionTxOperation; +import org.eclipse.osee.framework.database.operation.ParseWindowsDirectoryListingOperation; import org.eclipse.osee.framework.database.operation.PurgeUnusedBackingDataAndTransactions; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.server.admin.internal.Activator; @@ -150,6 +151,16 @@ public class ServerAdminCommandProvider implements CommandProvider { return Operations.executeAsJob(new ServerShutdownOperation(logger, ci), true, shutdownMutex); } + public Job _parse_dir(CommandInterpreter ci) { + OperationLogger logger = new CommandInterpreterLogger(ci); + String listingFile = ci.nextArgument(); + IOperation operation = + new ParseWindowsDirectoryListingOperation(Activator.getOseeDatabaseService(), + Activator.getOseeCachingService(), logger, listingFile); + + return Operations.executeAsJob(operation, false); + } + @Override public String getHelp() { StringBuilder sb = new StringBuilder(); @@ -167,6 +178,7 @@ public class ServerAdminCommandProvider implements CommandProvider { sb.append(" osee_shutdown [-oseeOnly] - immediately release the listening port then waits for all existing operations to finish. \n"); sb.append(" schedule <delay seconds> <iterations> <command> - runs the command after the specified delay and repeat given number of times\n"); sb.append(" purge_relation_type -force excute the operation, relationType1 ...\n"); + sb.append(" parse_dir - converts the given file into a formatted CSV file\n"); sb.append(String.format(" reload_cache %s? - reloads server caches\n", Arrays.deepToString(OseeCacheEnum.values()).replaceAll(",", " | "))); sb.append(String.format(" clear_cache %s? - decaches all objects from the specified caches\n", diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml b/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml index 2591f52..68d03bd 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml +++ b/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml @@ -1151,14 +1151,6 @@ </Operation> </extension> <extension - id="ParseWindowsDirectoryListing" - name="ParseWindowsDirectoryListing" - point="org.eclipse.osee.framework.ui.skynet.BlamOperation"> - <Operation - className="org.eclipse.osee.framework.ui.skynet.blam.operation.ParseWindowsDirectoryListing"> - </Operation> - </extension> - <extension point="org.eclipse.osee.framework.ui.skynet.BlamOperation"> <Operation className="org.eclipse.osee.framework.ui.skynet.blam.operation.FixTemplateContentArtifacts"> diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ParseWindowsDirectoryListing.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ParseWindowsDirectoryListing.java deleted file mode 100644 index 7fce426..0000000 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ParseWindowsDirectoryListing.java +++ b/dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 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.ui.skynet.blam.operation; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.util.Arrays; -import java.util.Collection; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam; -import org.eclipse.osee.framework.ui.skynet.blam.VariableMap; - -/** - * @author Ryan D. Brooks - */ -public class ParseWindowsDirectoryListing extends AbstractBlam { - private static final String DIRECTORY_PREFIX = " Directory of Y:\\"; - - @Override - public String getName() { - return "Parse Windows Directory Listing"; - } - - @Override - public void runOperation(VariableMap variableMap, IProgressMonitor monitor) throws Exception { - String listingFile = variableMap.getString("Directory Listing File"); - Matcher matcher = Pattern.compile("(\\d+/\\d+/\\d+).*<DIR>.*?SW\\\\(\\S+)\\s+(.*)").matcher(""); - BufferedWriter writer = new BufferedWriter(new FileWriter(Lib.removeExtension(listingFile) + ".csv")); - - String path = null; - for (String line : Lib.readListFromFile(listingFile)) { - if (line.startsWith(DIRECTORY_PREFIX)) { - path = line.substring(DIRECTORY_PREFIX.length()); - } else { - matcher.reset(line); - if (matcher.find()) { - String summary = matcher.group(1) + "|" + matcher.group(2) + "|" + path + "\\" + matcher.group(3); - if (!summary.endsWith(".")) { - writer.write(summary); - writer.write(Lib.lineSeparator); - } - } - } - } - writer.close(); - } - - @Override - public String getXWidgetsXml() { - return "<xWidgets><XWidget xwidgetType=\"XText\" displayName=\"Directory Listing File\" defaultValue=\"c:\\UserData\\cte.txt\" /></xWidgets>"; - } - - @Override - public Collection<String> getCategories() { - return Arrays.asList("Util"); - } -} |

