Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions convert.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@

@echo off
@rem ============================================================================
@rem seleniumCodeBuilder �ɂ��ϊ����������s���܂��B
@rem seleniumCodeBuilder による変換処理を実行します。
@rem ============================================================================

@rem --- �‹��ϐ���J�����g�f�B���N�g�������[�J�������܂��B
@rem --- 環境変数やカレントディレクトリをローカル化します。
setlocal

rem --- groovy �X�N���v�g�̊i�[�f�B���N�g���ɕύX���܂��B
rem --- groovy スクリプトの格納ディレクトリに変更します。
cd %~dp0\src\main\groovy
echo ------------------------------------------
echo --- �u�����������{���܂�...
echo --- 置換処理を実施します...
echo ------------------------------------------
java -cp .;../../../lib\* groovy.ui.GroovyMain SeleniumCodeBuilder.groovy %~dp0/input %~dp0/output %~dp0/setting.yaml
java -Dfile.encoding=UTF-8 -cp .;../../../lib/* groovy.ui.GroovyMain SeleniumCodeBuilder.groovy %~dp0/input %~dp0/output %~dp0/setting.yaml
echo.
echo ------------------------------------------
echo --- �p�b�P�[�W�K�w��ݒ肵�܂�...
echo --- パッケージ階層を設定します...
echo ------------------------------------------
java -cp .;../../../lib\* groovy.ui.GroovyMain PackageModifier.groovy %~dp0/output %~dp0/output
java -Dfile.encoding=UTF-8 -cp .;../../../lib/* groovy.ui.GroovyMain PackageModifier.groovy %~dp0/output %~dp0/output

@rem --- �����t���Ŗ{�o�b�`���N�����ꂽ�ꍇ�́Apause���s���܂���B
@rem --- 引数付きで本バッチが起動された場合は、pauseを行いません。
@if "%1"=="" (
pause
)

@rem --- �‹��ϐ����̃��[�J�������I�����܂��B
@rem --- 環境変数等のローカル化を終了します。
endlocal

@rem --- ����I�����܂��B
@rem --- 正常終了します。
exit /b 0

33 changes: 33 additions & 0 deletions convert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ----------------------------------------------------------------------------
# Copyright (c) Acroquest Technology Co, Ltd. All Rights Reserved.
# Please read the associated COPYRIGHTS file for more details.
#
# THE SOFTWARE IS PROVIDED BY Acroquest Technology Co., Ltd.,
# WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDER BE LIABLE FOR ANY
# CLAIM, DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
# OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
# ----------------------------------------------------------------------------

# ============================================================================
# seleniumCodeBuilder による変換処理を実行します。
# ============================================================================

# --- groovy スクリプトの格納ディレクトリに変更します。
cd $(dirname $0)
cd src/main/groovy
echo ------------------------------------------
echo --- 置換処理を実施します...
echo ------------------------------------------
java -cp .:../../../lib/* groovy.ui.GroovyMain SeleniumCodeBuilder.groovy ../../../input ../../../output ../../../setting.yaml

echo ------------------------------------------
echo --- パッケージ階層を設定します...
echo ------------------------------------------
java -cp .:../../../lib/* groovy.ui.GroovyMain PackageModifier.groovy ../../../output ../../../output

# --- 正常終了します。
exit 0

266 changes: 200 additions & 66 deletions setting.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/groovy/FileUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.util.Collections;
import java.util.List;

/**
* �t�@�C���V�X�e���֘A�̃��[�e�B���e�B�N���X�B
* ファイルシステム関連のユーティリティクラス。
*
*/
public class FileUtil {
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/JavaFileFilter.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.io.File
import java.io.FilenameFilter;

/**
* Java�t�@�C���̃t�B���^�����O�̂��߂̃N���X�B
* Javaファイルのフィルタリングのためのクラス。
*
*/
class JavaFileFilter implements FilenameFilter {
Expand Down
54 changes: 28 additions & 26 deletions src/main/groovy/PackageModifier.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,64 +13,64 @@

import java.io.File;

// �Ώۂ̃t�@�C����Root�t�H���_����̃p�b�P�[�W��lj�����B
// 対象のファイルにRootフォルダからのパッケージを追加する。
boolean isExecute = checkArgs(args);
if (!isExecute) {
println "�������I�����܂��B";
println "処理を終了します。";
return;
}

/**
* �����`�F�b�N���s���B
* 引数チェックを行う。
*
*/
def checkArgs(String[] values) {
String commandLineMessage = "�g�p�@: groovy -e targetPath(file or directory) outputPath(directory) settingPath";
// ��‚��Ȃ����NG
String commandLineMessage = "必要な引数: targetPath(file or directory) outputPath(directory)";
// 一つもなければNG
if (values.size() <= 1) {
println "����������܂���B";
println "引数が足りません。";
println commandLineMessage;
return false;
}

// �������̃t�@�C���������̓t�H���_�����邩�m�F����B
// 第一引数のファイルもしくはフォルダがあるか確認する。
String inputPath = values[0];
File file = new File(inputPath);
if(file.exists() == false) {
println "�ϊ���̃p�X�Ƀt�@�C���������̓t�H���_������܂���Bpath=" + file.getAbsolutePath();
println "変換先のパスにファイルもしくはフォルダがありません。path=" + file.getAbsolutePath();
println commandLineMessage;
return false;
}

// �o�̓t�@�C����ɂ��łɃt�@�C��������ꍇ�͏����𒆒f����B
// 出力ファイル先にすでにファイルがある場合は処理を中断する。
File outputFolder = new File(values[1]);
if (outputFolder.exists()) {
if (!outputFolder.isDirectory()) {
println "�o�͐悪�t�H���_�ł͂���܂���Bpath=" + outputFolder.getAbsolutePath();
println "出力先がフォルダではありません。path=" + outputFolder.getAbsolutePath();
println commandLineMessage;
return false;
}
}

// java �t�@�C�������邩�`�F�b�N����B
// java ファイルがあるかチェックする。
if (file.isDirectory()) {
File[] javaFiles = FileUtil.getFileWithSubFolder(file, new JavaFileFilter());
if (javaFiles == null || javaFiles.length == 0) {
println "�ϊ��Ώۂ�java�t�@�C��������܂���B";
println "変換対象のjavaファイルがありません。";
println commandLineMessage;
return false;
}
} else {
if (!file.name.endsWith(".java")) {
println "�ϊ��Ώۂ̃t�@�C����java�t�@�C���ł͂���܂���B";
println "変換対象のファイルはjavaファイルではありません。";
println commandLineMessage;
return false;
}
}
return true;
}

// �ϊ���̃t�@�C�����w�肷��B
// 変換対象のファイルを指定する。
File target = new File(args[0]);
File[] targets;
if (target.isDirectory()) {
Expand All @@ -79,19 +79,20 @@ if (target.isDirectory()) {
targets = [target] as File[];
}

// �o�͐�̃t�H���_���쐬����B
// 出力先のフォルダを作成する。
File output = new File(args[1]);
output.mkdirs();
for (File targetFile : targets) {
permutation(targetFile, output, target);
}
println "�������I�����܂��B";
println "処理を終了します。";


/**
* �Ώۂ̃t�@�C����u�����A�o�̓t�H���_�ɏo�͂���B
* @param file �u���t�@�C��
* @param outputPath �o�͐�t�@�C���p�X
* 対象のファイルのパッケージ指定をフォルダ構成に準じて置換し、出力フォルダに出力する。
* @param targetPath 置換対象ファイル
* @param outputPath 出力先ファイルパス
* @param rootFolder 置換対象ファイルまたはフォルダルート
*/
def permutation(File targetPath, File outputPath, File rootFolder) {
StringBuilder fileRead = new StringBuilder();
Expand All @@ -110,12 +111,13 @@ def permutation(File targetPath, File outputPath, File rootFolder) {
System.out.println( ex );
}

// �o�͐�̃p�X���擾����
// 出力先のパスを取得する
String rootPath = rootFolder.getAbsolutePath();
String targetFilePath = targetPath.getAbsolutePath();
File outputFile;
String packageName = "";
if (targetPath.absolutePath.equals(rootFolder.absolutePath))
if (targetPath.absolutePath.equals(rootFolder.absolutePath)
|| targetPath.getParent().equals(rootFolder.absolutePath)) // 20170317 - ファイルがフォルダルートに置かれた場合
{
String fileName = targetPath.getName();
outputFile = new File(outputPath, fileName);
Expand All @@ -129,7 +131,7 @@ def permutation(File targetPath, File outputPath, File rootFolder) {
}


// �ݒ�t�@�C����ǂݍ��݁A�u�������{����B
// 設定ファイルを読み込み、置換を実施する。
String output = fileRead.toString();
String before = "package com\\.example\\.tests;";
String after = "";
Expand All @@ -139,14 +141,14 @@ def permutation(File targetPath, File outputPath, File rootFolder) {
}
output = output.replaceAll(before, after);

// �ۑ�����B
// 保存する。
try {

if (outputFile.exists()) {
println "�o�͐�ɂ��łɃt�@�C�������邽�߁A�㏑�����܂��B";
println "出力先にすでにファイルがあるため、上書きします。";
boolean isDelete = outputFile.delete();
if (!isDelete) {
println "�㏑���ł��܂���B�ۑ����X�L�b�v���܂��Bpath:" + outputFile.absolutePath;
println "上書きできません。保存をスキップします。path:" + outputFile.absolutePath;
return;
}
}
Expand All @@ -155,7 +157,7 @@ def permutation(File targetPath, File outputPath, File rootFolder) {
OutputStreamWriter filewriter = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8");
filewriter.write(output);
filewriter.close();
println "�u����̃t�@�C����ۑ����܂����B path:" + outputFile.absolutePath;
println "置換後のファイルを保存しました。 path:" + outputFile.absolutePath;
} catch ( IOException ex ) {
ex.printStackTrace();
}
Expand Down
Loading