OSDN Git Service

Macの起動ランチャをBashから独自Objcコードに変更
authorseraphy <seraphy@users.osdn.me>
Wed, 2 Jan 2019 22:07:10 +0000 (07:07 +0900)
committerseraphy <seraphy@users.osdn.me>
Wed, 2 Jan 2019 22:07:10 +0000 (07:07 +0900)
13 files changed:
.gitignore
pom.xml
src/JavaLaunch/JavaLaunch.xcodeproj/project.pbxproj [new file with mode: 0644]
src/JavaLaunch/JavaLaunch.xcodeproj/project.xcworkspace/contents.xcworkspacedata [new file with mode: 0644]
src/JavaLaunch/JavaLaunch.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist [new file with mode: 0644]
src/JavaLaunch/JavaLaunch.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings [new file with mode: 0644]
src/JavaLaunch/JavaLaunch.xcodeproj/xcshareddata/xcschemes/JavaLaunch.xcscheme [new file with mode: 0644]
src/JavaLaunch/JavaLaunch/main.m [new file with mode: 0644]
src/main/attachment/bundle/CharacterManaJ.app/Contents/Info.plist
src/main/attachment/bundle/CharacterManaJ.app/Contents/MacOS/JavaLaunch [new file with mode: 0755]
src/main/attachment/bundle/CharacterManaJ.app/Contents/MacOS/java_launch.sh [deleted file]
src/main/attachment/bundle/CharacterManaJ.app/Contents/Resources/en.lproj/Localizable.strings [new file with mode: 0644]
src/main/attachment/bundle/CharacterManaJ.app/Contents/Resources/ja.lproj/Localizable.strings [new file with mode: 0644]

index d839045..7b2afda 100644 (file)
@@ -4,3 +4,21 @@
 /bin
 /target/
 .DS_Store
+
+# Xcode (from gitignore.io)
+build/
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata
+*.xccheckout
+*.moved-aside
+DerivedData
+*.hmap
+*.ipa
+*.xcuserstate
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 7a22495..2e98869 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                                                                                </copy>
 
                                                                                <chmod dir="${project.build.directory}/appbundle/CharacterManaJ.app/Contents/MacOS"
-                                                                                       perm="a+rx" includes="**/*.sh"/>
+                                                                                       perm="a+rx" includes="JavaLaunch"/>
                                                                                <copy todir="${project.build.directory}/appbundle">
                                                                                        <fileset dir="${project.basedir}/src/main/attachment">
                                                                                                <include name="README_mac.txt"/>
diff --git a/src/JavaLaunch/JavaLaunch.xcodeproj/project.pbxproj b/src/JavaLaunch/JavaLaunch.xcodeproj/project.pbxproj
new file mode 100644 (file)
index 0000000..b1a3444
--- /dev/null
@@ -0,0 +1,283 @@
+// !$*UTF8*$!
+{
+       archiveVersion = 1;
+       classes = {
+       };
+       objectVersion = 50;
+       objects = {
+
+/* Begin PBXBuildFile section */
+               2EC90F9121DC4F1B00F295DC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2EC90F9021DC4F1B00F295DC /* main.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+               2EC90F8B21DC4F1B00F295DC /* CopyFiles */ = {
+                       isa = PBXCopyFilesBuildPhase;
+                       buildActionMask = 2147483647;
+                       dstPath = /usr/share/man/man1/;
+                       dstSubfolderSpec = 0;
+                       files = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 1;
+               };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+               2EC90F8D21DC4F1B00F295DC /* JavaLaunch */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = JavaLaunch; sourceTree = BUILT_PRODUCTS_DIR; };
+               2EC90F9021DC4F1B00F295DC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+               2EC90F8A21DC4F1B00F295DC /* Frameworks */ = {
+                       isa = PBXFrameworksBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+               2EC90F8421DC4F1B00F295DC = {
+                       isa = PBXGroup;
+                       children = (
+                               2EC90F8F21DC4F1B00F295DC /* JavaLaunch */,
+                               2EC90F8E21DC4F1B00F295DC /* Products */,
+                       );
+                       sourceTree = "<group>";
+               };
+               2EC90F8E21DC4F1B00F295DC /* Products */ = {
+                       isa = PBXGroup;
+                       children = (
+                               2EC90F8D21DC4F1B00F295DC /* JavaLaunch */,
+                       );
+                       name = Products;
+                       sourceTree = "<group>";
+               };
+               2EC90F8F21DC4F1B00F295DC /* JavaLaunch */ = {
+                       isa = PBXGroup;
+                       children = (
+                               2EC90F9021DC4F1B00F295DC /* main.m */,
+                       );
+                       path = JavaLaunch;
+                       sourceTree = "<group>";
+               };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+               2EC90F8C21DC4F1B00F295DC /* JavaLaunch */ = {
+                       isa = PBXNativeTarget;
+                       buildConfigurationList = 2EC90F9421DC4F1B00F295DC /* Build configuration list for PBXNativeTarget "JavaLaunch" */;
+                       buildPhases = (
+                               2EC90F8921DC4F1B00F295DC /* Sources */,
+                               2EC90F8A21DC4F1B00F295DC /* Frameworks */,
+                               2EC90F8B21DC4F1B00F295DC /* CopyFiles */,
+                       );
+                       buildRules = (
+                       );
+                       dependencies = (
+                       );
+                       name = JavaLaunch;
+                       productName = JavaLaunch;
+                       productReference = 2EC90F8D21DC4F1B00F295DC /* JavaLaunch */;
+                       productType = "com.apple.product-type.tool";
+               };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+               2EC90F8521DC4F1B00F295DC /* Project object */ = {
+                       isa = PBXProject;
+                       attributes = {
+                               LastUpgradeCheck = 1010;
+                               ORGANIZATIONNAME = seraphy;
+                               TargetAttributes = {
+                                       2EC90F8C21DC4F1B00F295DC = {
+                                               CreatedOnToolsVersion = 10.1;
+                                       };
+                               };
+                       };
+                       buildConfigurationList = 2EC90F8821DC4F1B00F295DC /* Build configuration list for PBXProject "JavaLaunch" */;
+                       compatibilityVersion = "Xcode 9.3";
+                       developmentRegion = en;
+                       hasScannedForEncodings = 0;
+                       knownRegions = (
+                               en,
+                       );
+                       mainGroup = 2EC90F8421DC4F1B00F295DC;
+                       productRefGroup = 2EC90F8E21DC4F1B00F295DC /* Products */;
+                       projectDirPath = "";
+                       projectRoot = "";
+                       targets = (
+                               2EC90F8C21DC4F1B00F295DC /* JavaLaunch */,
+                       );
+               };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+               2EC90F8921DC4F1B00F295DC /* Sources */ = {
+                       isa = PBXSourcesBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                               2EC90F9121DC4F1B00F295DC /* main.m in Sources */,
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+               2EC90F9221DC4F1B00F295DC /* Debug */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               ALWAYS_SEARCH_USER_PATHS = NO;
+                               CLANG_ANALYZER_NONNULL = YES;
+                               CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+                               CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
+                               CLANG_CXX_LIBRARY = "libc++";
+                               CLANG_ENABLE_MODULES = YES;
+                               CLANG_ENABLE_OBJC_ARC = YES;
+                               CLANG_ENABLE_OBJC_WEAK = YES;
+                               CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+                               CLANG_WARN_BOOL_CONVERSION = YES;
+                               CLANG_WARN_COMMA = YES;
+                               CLANG_WARN_CONSTANT_CONVERSION = YES;
+                               CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+                               CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+                               CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+                               CLANG_WARN_EMPTY_BODY = YES;
+                               CLANG_WARN_ENUM_CONVERSION = YES;
+                               CLANG_WARN_INFINITE_RECURSION = YES;
+                               CLANG_WARN_INT_CONVERSION = YES;
+                               CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+                               CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+                               CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+                               CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+                               CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+                               CLANG_WARN_STRICT_PROTOTYPES = YES;
+                               CLANG_WARN_SUSPICIOUS_MOVE = YES;
+                               CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+                               CLANG_WARN_UNREACHABLE_CODE = YES;
+                               CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+                               CODE_SIGN_IDENTITY = "-";
+                               COPY_PHASE_STRIP = NO;
+                               DEBUG_INFORMATION_FORMAT = dwarf;
+                               ENABLE_STRICT_OBJC_MSGSEND = YES;
+                               ENABLE_TESTABILITY = YES;
+                               GCC_C_LANGUAGE_STANDARD = gnu11;
+                               GCC_DYNAMIC_NO_PIC = NO;
+                               GCC_NO_COMMON_BLOCKS = YES;
+                               GCC_OPTIMIZATION_LEVEL = 0;
+                               GCC_PREPROCESSOR_DEFINITIONS = (
+                                       "DEBUG=1",
+                                       "$(inherited)",
+                               );
+                               GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+                               GCC_WARN_UNDECLARED_SELECTOR = YES;
+                               GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+                               GCC_WARN_UNUSED_FUNCTION = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               MACOSX_DEPLOYMENT_TARGET = 10.14;
+                               MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+                               MTL_FAST_MATH = YES;
+                               ONLY_ACTIVE_ARCH = YES;
+                               SDKROOT = macosx;
+                       };
+                       name = Debug;
+               };
+               2EC90F9321DC4F1B00F295DC /* Release */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               ALWAYS_SEARCH_USER_PATHS = NO;
+                               CLANG_ANALYZER_NONNULL = YES;
+                               CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+                               CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
+                               CLANG_CXX_LIBRARY = "libc++";
+                               CLANG_ENABLE_MODULES = YES;
+                               CLANG_ENABLE_OBJC_ARC = YES;
+                               CLANG_ENABLE_OBJC_WEAK = YES;
+                               CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+                               CLANG_WARN_BOOL_CONVERSION = YES;
+                               CLANG_WARN_COMMA = YES;
+                               CLANG_WARN_CONSTANT_CONVERSION = YES;
+                               CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+                               CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+                               CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+                               CLANG_WARN_EMPTY_BODY = YES;
+                               CLANG_WARN_ENUM_CONVERSION = YES;
+                               CLANG_WARN_INFINITE_RECURSION = YES;
+                               CLANG_WARN_INT_CONVERSION = YES;
+                               CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+                               CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+                               CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+                               CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+                               CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+                               CLANG_WARN_STRICT_PROTOTYPES = YES;
+                               CLANG_WARN_SUSPICIOUS_MOVE = YES;
+                               CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+                               CLANG_WARN_UNREACHABLE_CODE = YES;
+                               CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+                               CODE_SIGN_IDENTITY = "-";
+                               COPY_PHASE_STRIP = NO;
+                               DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                               ENABLE_NS_ASSERTIONS = NO;
+                               ENABLE_STRICT_OBJC_MSGSEND = YES;
+                               GCC_C_LANGUAGE_STANDARD = gnu11;
+                               GCC_NO_COMMON_BLOCKS = YES;
+                               GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+                               GCC_WARN_UNDECLARED_SELECTOR = YES;
+                               GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+                               GCC_WARN_UNUSED_FUNCTION = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               MACOSX_DEPLOYMENT_TARGET = 10.14;
+                               MTL_ENABLE_DEBUG_INFO = NO;
+                               MTL_FAST_MATH = YES;
+                               SDKROOT = macosx;
+                       };
+                       name = Release;
+               };
+               2EC90F9521DC4F1B00F295DC /* Debug */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = NO;
+                               CODE_SIGN_STYLE = Automatic;
+                               MACOSX_DEPLOYMENT_TARGET = 10.6;
+                               PRODUCT_NAME = "$(TARGET_NAME)";
+                       };
+                       name = Debug;
+               };
+               2EC90F9621DC4F1B00F295DC /* Release */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = NO;
+                               CODE_SIGN_STYLE = Automatic;
+                               MACOSX_DEPLOYMENT_TARGET = 10.6;
+                               PRODUCT_NAME = "$(TARGET_NAME)";
+                       };
+                       name = Release;
+               };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+               2EC90F8821DC4F1B00F295DC /* Build configuration list for PBXProject "JavaLaunch" */ = {
+                       isa = XCConfigurationList;
+                       buildConfigurations = (
+                               2EC90F9221DC4F1B00F295DC /* Debug */,
+                               2EC90F9321DC4F1B00F295DC /* Release */,
+                       );
+                       defaultConfigurationIsVisible = 0;
+                       defaultConfigurationName = Release;
+               };
+               2EC90F9421DC4F1B00F295DC /* Build configuration list for PBXNativeTarget "JavaLaunch" */ = {
+                       isa = XCConfigurationList;
+                       buildConfigurations = (
+                               2EC90F9521DC4F1B00F295DC /* Debug */,
+                               2EC90F9621DC4F1B00F295DC /* Release */,
+                       );
+                       defaultConfigurationIsVisible = 0;
+                       defaultConfigurationName = Release;
+               };
+/* End XCConfigurationList section */
+       };
+       rootObject = 2EC90F8521DC4F1B00F295DC /* Project object */;
+}
diff --git a/src/JavaLaunch/JavaLaunch.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/src/JavaLaunch/JavaLaunch.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644 (file)
index 0000000..7133b13
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+   version = "1.0">
+   <FileRef
+      location = "self:JavaLaunch.xcodeproj">
+   </FileRef>
+</Workspace>
diff --git a/src/JavaLaunch/JavaLaunch.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/src/JavaLaunch/JavaLaunch.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
new file mode 100644 (file)
index 0000000..18d9810
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>IDEDidComputeMac32BitWarning</key>
+       <true/>
+</dict>
+</plist>
diff --git a/src/JavaLaunch/JavaLaunch.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/src/JavaLaunch/JavaLaunch.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
new file mode 100644 (file)
index 0000000..0c67376
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict/>
+</plist>
diff --git a/src/JavaLaunch/JavaLaunch.xcodeproj/xcshareddata/xcschemes/JavaLaunch.xcscheme b/src/JavaLaunch/JavaLaunch.xcodeproj/xcshareddata/xcschemes/JavaLaunch.xcscheme
new file mode 100644 (file)
index 0000000..dc16493
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "1010"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "2EC90F8C21DC4F1B00F295DC"
+               BuildableName = "JavaLaunch"
+               BlueprintName = "JavaLaunch"
+               ReferencedContainer = "container:JavaLaunch.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES">
+      <Testables>
+      </Testables>
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "2EC90F8C21DC4F1B00F295DC"
+            BuildableName = "JavaLaunch"
+            BlueprintName = "JavaLaunch"
+            ReferencedContainer = "container:JavaLaunch.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Release"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "2EC90F8C21DC4F1B00F295DC"
+            BuildableName = "JavaLaunch"
+            BlueprintName = "JavaLaunch"
+            ReferencedContainer = "container:JavaLaunch.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "2EC90F8C21DC4F1B00F295DC"
+            BuildableName = "JavaLaunch"
+            BlueprintName = "JavaLaunch"
+            ReferencedContainer = "container:JavaLaunch.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>
diff --git a/src/JavaLaunch/JavaLaunch/main.m b/src/JavaLaunch/JavaLaunch/main.m
new file mode 100644 (file)
index 0000000..55ecf0e
--- /dev/null
@@ -0,0 +1,162 @@
+//
+//  main.m
+//  JavaLaunch
+//
+//  Created by seraphy on 2019/01/02.
+//  Copyright © 2019 seraphy. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <Cocoa/Cocoa.h>
+
+#define JAVA_LAUNCH_ERROR "JavaLaunchError"
+#define UNSPECIFIED_ERROR "An unknown error occurred."
+
+NSString *FindJavaHome() {
+    NSTask *task = [[NSTask alloc] init];
+    NSPipe *pipe  = [NSPipe pipe];
+    
+    [task setLaunchPath:@"/usr/libexec/java_home"];
+    [task setArguments: [NSArray arrayWithObjects: @"-v", nil]];
+    [task setStandardOutput: pipe];
+    [task launch];
+    
+    NSFileHandle *handle = [pipe fileHandleForReading];
+    NSData *data = [handle readDataToEndOfFile];
+    NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+    
+    [task waitUntilExit];
+    int exitCode = [task terminationStatus];
+    if (exitCode != 0) {
+        NSLog(@"not found system java_home");
+        return nil;
+    }
+    NSLog(@"found system java_home=%@", result);
+    return result;
+}
+
+int main(int argc, const char * argv[]) {
+    int exitCode = 0;
+    @autoreleasepool {
+        @try {
+            // メインバンドル
+            NSBundle *mainBundle = [NSBundle mainBundle];
+            
+            // *.appのディレクトリを取得
+            NSString *mainBundlePath = [mainBundle bundlePath];
+            NSLog(@"mainBundlePath=%@", mainBundlePath);
+            
+            // 実行可能jarの場所
+            NSString *jarPath = [[mainBundlePath stringByAppendingPathComponent:@"Contents"] stringByAppendingPathComponent: [[mainBundle infoDictionary] objectForKey:@"ExecutableJar"]];
+            NSLog(@"jarPath=%@", jarPath);
+            
+            // バンドルJREの場所を探索する
+            NSString *pluginJreDir = [mainBundlePath stringByAppendingPathComponent:@"Contents/Plugins/JRE"];
+            NSLog(@"pluginJreDir=%@", pluginJreDir);
+            
+            NSString *jreDir = pluginJreDir;
+            
+            NSFileManager *fileManager = [NSFileManager defaultManager];
+            NSString *path = [pluginJreDir stringByAppendingPathComponent:@"Home/bin/java"];
+            if ([fileManager fileExistsAtPath: path]) {
+                // パターン1 Home/bin/java
+                jreDir = [pluginJreDir stringByAppendingPathComponent:@"Home"];
+            } else {
+                // パターン2 bin/java
+                path = [pluginJreDir stringByAppendingPathComponent:@"bin/java"];
+                if (![fileManager fileExistsAtPath: path]) {
+                    // バンドルJREがない場合は環境変数JAVA_HOMEがあれば、それを優先する
+                    jreDir = [[[NSProcessInfo processInfo]environment]objectForKey:@"JAVA_HOME"];
+                    if (jreDir == nil) {
+                        // 環境変数JAVA_HOMEがなければ/usr/libexec/java_homeで問い合わせる
+                        jreDir = FindJavaHome();
+                    }
+                }   
+            }
+            NSLog(@"JreDir=%@", jreDir);
+            if (jreDir == nil) {
+                // JAVA_HOMEを特定できなければエラーダイアログ表示
+                NSString *title = [mainBundle localizedStringForKey: @"JavaDirectoryNotFound" value:@"JRE Not Found Error" table:@"Localizable"];
+                [[NSException exceptionWithName:@JAVA_LAUNCH_ERROR reason:title userInfo:nil] raise];
+            }
+            
+            // アプリケーション名を取得(ローカライズされたもの)
+            NSString *displayAppName;
+            displayAppName = [[mainBundle localizedInfoDictionary] objectForKey:@"CFBundleDisplayName"];
+            NSLog(@"displayAppName=%@", displayAppName);
+            printf("%s\n", [displayAppName UTF8String]);
+            
+            //
+            NSMutableArray *jvmOptions = [[[mainBundle infoDictionary] objectForKey:@"JVMOptions"] mutableCopy];
+            if (jvmOptions == nil) {
+                jvmOptions = [NSMutableArray array];
+            }
+            
+            // バンドル名
+            NSString *bundleName = [[mainBundle infoDictionary] objectForKey:@"CFBundleName"];
+            NSLog(@"bundleName=%@", bundleName);
+            
+            // ユーザー定義オプションの読み込み
+            NSString *userJvmOptionPath = [NSHomeDirectory() stringByAppendingPathComponent: [NSString stringWithFormat:@"/Library/%@/jvm_options", bundleName]];
+            if ([fileManager fileExistsAtPath: userJvmOptionPath]) {
+                NSString* fileContents = [NSString stringWithContentsOfFile:userJvmOptionPath
+                                                                   encoding:NSUTF8StringEncoding error:nil];
+                NSArray* allLinedStrings = [fileContents componentsSeparatedByCharactersInSet:
+                                            [NSCharacterSet newlineCharacterSet]];
+                // 同一のキーが指定されている場合はRightMostとなることを期待している。(厳密には仕様に定義されていない。)
+                for (id line in allLinedStrings) {
+                    NSString *option = [line stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
+                    if (![option hasPrefix:@"#"] && [option length] > 0) {
+                        NSLog(@"option: %@", line);
+                        [jvmOptions addObject: option];
+                    }
+                }
+            }
+            
+            // Java起動引数の組み立て
+            NSMutableArray *launchArgs = [NSMutableArray arrayWithObjects:[@"-Xdock:name=" stringByAppendingString:displayAppName], nil];
+            [launchArgs addObjectsFromArray: jvmOptions];
+            [launchArgs addObject:@"-jar"];
+            [launchArgs addObject:jarPath];
+            // javaを起動する
+            NSPipe *pipe  = [NSPipe pipe];
+            NSTask *javaTask = [[NSTask alloc] init];
+            [javaTask setLaunchPath: [jreDir stringByAppendingPathComponent: @"bin/java"]];
+            [javaTask setArguments: launchArgs];
+            [javaTask setStandardError: pipe];
+            
+            NSTimeInterval beginTime = [NSDate timeIntervalSinceReferenceDate];
+            [javaTask launch];
+            
+            NSFileHandle *handle = [pipe fileHandleForReading];
+            NSData *data = [handle readDataToEndOfFile];
+            NSString *javaError = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+            if ([javaError length] > 0) {
+                NSLog(@"Error Message=%@", javaError);
+            }
+            
+            [javaTask waitUntilExit];
+            NSTimeInterval endTime = [NSDate timeIntervalSinceReferenceDate];
+            
+            exitCode = [javaTask terminationStatus];
+            NSLog(@"exitCode=%d", exitCode);
+            
+            NSTimeInterval span = endTime - beginTime;
+            if (span < 5 && exitCode != 0) {
+                // Javaの実行直後にエラーで終了している場合は、クラスロードエラーの可能性が高い。
+                NSString *title = [mainBundle localizedStringForKey: @"JRELoadError" value:@"JRE Load Error" table:nil];
+                NSString *reason = [NSString stringWithFormat:@"%@\n%@", title, javaError];
+                [[NSException exceptionWithName:@JAVA_LAUNCH_ERROR reason: reason userInfo:nil] raise];
+            }
+            
+        } @catch(NSException *exception) {
+            NSLog(@"error=%@", [exception reason]);
+            NSAlert *alert = [[NSAlert alloc] init];
+            [alert setAlertStyle:NSCriticalAlertStyle];
+            [alert setMessageText:[exception reason]];
+            [alert runModal];
+            exitCode = 1;
+        }
+    }
+    return exitCode;
+}
index 6b35059..e174d0b 100644 (file)
@@ -5,7 +5,7 @@
     <key>CFBundleDevelopmentRegion</key>
     <string>English</string>
     <key>CFBundleExecutable</key>
-    <string>java_launch.sh</string>
+    <string>JavaLaunch</string>
     <key>CFBundleIconFile</key>
     <string>icon.icns</string>
     <key>CFBundleIdentifier</key>
@@ -30,5 +30,7 @@
     <true/>
     <key>NSSupportsAutomaticGraphicsSwitching</key>
     <true/>
+    <key>ExecutableJar</key>
+    <string>Resources/CharacterManaJ.jar</string>
   </dict>
 </plist>
diff --git a/src/main/attachment/bundle/CharacterManaJ.app/Contents/MacOS/JavaLaunch b/src/main/attachment/bundle/CharacterManaJ.app/Contents/MacOS/JavaLaunch
new file mode 100755 (executable)
index 0000000..51d1669
Binary files /dev/null and b/src/main/attachment/bundle/CharacterManaJ.app/Contents/MacOS/JavaLaunch differ
diff --git a/src/main/attachment/bundle/CharacterManaJ.app/Contents/MacOS/java_launch.sh b/src/main/attachment/bundle/CharacterManaJ.app/Contents/MacOS/java_launch.sh
deleted file mode 100755 (executable)
index c5caf04..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-#! /bin/bash
-
-APPNAME="CharacterManaJ"
-JARNAME="CharacterManaJ.jar"
-
-# JVMオプション
-declare -a jvm_options=()
-
-# 相対パスから絶対パスに変換する
-function realpath() {
-    [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
-}
-
-# エラーを表示する
-function ShowMessage() {
-    if [[ -x /usr/bin/osascript ]]; then
-        /usr/bin/osascript -e "display alert \"$APPNAME\" message \"$1\""
-    else
-        echo "$APPNAME -- $1"
-    fi
-}
-
-# JVMに指定するオプションのテキストファイルをjvm_options配列に読み込む
-function read_jvm_options() {
-    while IFS='' read -r line || [[ -n $line ]]; do
-        line="${line//[$'\r\n']}" # 行端記号の除去(空白は残す)
-        trimline="${line//[$'\t\r\n ']}" # 空行判定のためタブ、行端、空白を除去
-        if [[ -n $trimline ]]; then
-            jvm_options+=("$line")
-        fi
-    done < "$1"
-}
-
-# このスクリプト基準のパスを求める
-SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
-RESOURCE_DIR="$(realpath "$SCRIPT_DIR/../Resources")"
-
-# JVMオプションがあれば読み取る
-if [[ -f "$RESOURCE_DIR/jvm_options" ]]; then
-    read_jvm_options "$RESOURCE_DIR/jvm_options"
-fi
-# JVMオプション(ユーザーディレクトリ上)
-if [[ -f "${HOME}/Library/${APPNAME}/jvm_options" ]]; then
-    read_jvm_options "${HOME}/Library/${APPNAME}/jvm_options"
-fi
-
-# JREの位置を検索する
-PLUGINS_JRE_DIR="$(realpath "${SCRIPT_DIR}/../Plugins/JRE")"
-if [[ -x "${PLUGINS_JRE_DIR}/Home/bin/java" ]]; then
-    # バンドル内にある場合(パターン1)
-    JAVA_HOME="$(realpath "${PLUGINS_JRE_DIR}/Home")"
-elif [[ -x "${PLUGINS_JRE_DIR}/bin/java" ]]; then
-    # バンドル内にある場合(パターン2)
-    JAVA_HOME="$(realpath "${PLUGINS_JRE_DIR}")"
-else
-    # バンドル内にない場合で、環境変数JAVA_HOMEがあれば、それを用いる。
-    # 環境変数JAVA_HOMEがなければ、/usr/libexec/java_home があれば、それを使う
-    if [[ -z "$JAVA_HOME" ]]; then
-        if [[ -x "/usr/libexec/java_home" ]]; then
-            JAVA_HOME="$(/usr/libexec/java_home)"
-            if [[ $? -ne 0 ]]; then
-                # java_homeがエラーを返すならばJavaが無いものと見なす
-                JAVA_HOME=""
-            fi
-        fi
-    fi
-fi
-
-if [[ -z "$JAVA_HOME" ]]; then
-    which java 2>/dev/null
-    if [[ $? -ne 0 ]]; then
-        # JAVA_HOMEが設定されておらず、且つ、javaにパスが通ってない場合はエラー
-        ShowMessage "Could not find Java SE Runtime Environment."
-        exit 2
-    fi
-    # JAVA_HOMEは未設定だがパスが通っていれば継続する
-    JAVA_CMD="java"
-else
-    # JAVA_HOMEが特定されている場合は、それを用いる
-    export JAVA_HOME
-    JAVA_CMD="$JAVA_HOME/bin/java"
-fi
-
-# JAVAをオプションとJARを指定して起動する
-if [[ -f $RESOURCE_DIR/$JARNAME ]]; then
-       # アプリケーション名とロケールの取得
-       APPTITLE=( $("$JAVA_CMD" -jar "$RESOURCE_DIR/$JARNAME" --show-appinfo) )
-       if [[ $? -ne 0 ]]; then
-               # JAVAの起動に失敗した場合
-        ShowMessage "Could not launch Java SE Runtime Environment. ${APPNAME}"
-        exit 1
-       fi
-
-       # アプリケーションの起動
-    "$JAVA_CMD" ${jvm_options[@]} "-Xdock:name=${APPTITLE[0]}" -jar "$RESOURCE_DIR/$JARNAME" || ShowMessage "Failed to launch ${APPNAME}"
-else
-    ShowMessage "$JARNAME is not found."
-fi
diff --git a/src/main/attachment/bundle/CharacterManaJ.app/Contents/Resources/en.lproj/Localizable.strings b/src/main/attachment/bundle/CharacterManaJ.app/Contents/Resources/en.lproj/Localizable.strings
new file mode 100644 (file)
index 0000000..7054c22
--- /dev/null
@@ -0,0 +1,2 @@
+"JRELoadError" = "Unable to load Java Runtime Environment.";
+"JavaDirectoryNotFound" = "Unable to enumerate Java directory contents.";
diff --git a/src/main/attachment/bundle/CharacterManaJ.app/Contents/Resources/ja.lproj/Localizable.strings b/src/main/attachment/bundle/CharacterManaJ.app/Contents/Resources/ja.lproj/Localizable.strings
new file mode 100644 (file)
index 0000000..835c18e
--- /dev/null
@@ -0,0 +1,2 @@
+"JRELoadError" = "Javaの起動に失敗しました。";
+"JavaDirectoryNotFound" = "Javaランタイムが見つかりません";